Skip to content

Commit

Permalink
to mathml text
Browse files Browse the repository at this point in the history
  • Loading branch information
lluvz committed Nov 3, 2023
1 parent bb82eb6 commit 5e14766
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions demo/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ keyboard_button.addEventListener('pointerdown', () => {
soft_keyboard.container.style.display = 'none'
}
})

4 changes: 4 additions & 0 deletions demo/res/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/mathio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ export class MathIO {
private warn(warning: string) {
if(this._warn_handle) this._warn_handle(warning)
}
to_ml_text(): string {
let result;
let prev_e = this.cursor.previousElementSibling;
if(prev_e) {
this.cursor.remove();
result = this.root_node.innerHTML;
prev_e.insertAdjacentElement('afterend', this.cursor);
return result;
}
let next_e = this.cursor.nextElementSibling;
if(next_e) {
this.cursor.remove();
result = this.root_node.innerHTML;
next_e.insertAdjacentElement('beforebegin', this.cursor);
return result
}
let parent = this.cursor.parentElement as Element;
this.cursor.remove();
result = this.root_node.innerHTML;
parent.appendChild(this.cursor);
return result;
}
on_pointerdown(event: PointerEvent) {
let e = event.target;
if(!(e instanceof Element)) return;
Expand Down
4 changes: 2 additions & 2 deletions src/soft_keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ function more_keys(on_key: (key: string) => void): HTMLElement {
result.style.width = '10%'
let svg = inner_svg()
result.appendChild(svg)
let polyline = svg_polyline('20,40 20,80 60,80 60,40');
let polygon = svg_polygon('40,20 80,20 80,60 60,60 60,40 40,40');
let polyline = svg_polyline('20,40 20,80 60,80 60,40 20,40');
let polygon = svg_polygon('40,20 80,20 80,60 60,60 60,40 40,40 40,20');
svg.append(polygon, polyline);
return result
}
Expand Down
1 change: 1 addition & 0 deletions target/mathio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export declare class MathIO {
set vertical_fraction(setting: boolean);
constructor();
private warn;
to_ml_text(): string;
on_pointerdown(event: PointerEvent): void;
on_key(key: string): void;
private start_completing;
Expand Down
22 changes: 22 additions & 0 deletions target/mathio.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ export class MathIO {
if (this._warn_handle)
this._warn_handle(warning);
}
to_ml_text() {
let result;
let prev_e = this.cursor.previousElementSibling;
if (prev_e) {
this.cursor.remove();
result = this.root_node.innerHTML;
prev_e.insertAdjacentElement('afterend', this.cursor);
return result;
}
let next_e = this.cursor.nextElementSibling;
if (next_e) {
this.cursor.remove();
result = this.root_node.innerHTML;
next_e.insertAdjacentElement('beforebegin', this.cursor);
return result;
}
let parent = this.cursor.parentElement;
this.cursor.remove();
result = this.root_node.innerHTML;
parent.appendChild(this.cursor);
return result;
}
on_pointerdown(event) {
var _a;
let e = event.target;
Expand Down
4 changes: 2 additions & 2 deletions target/soft_keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ function more_keys(on_key) {
result.style.width = '10%';
let svg = inner_svg();
result.appendChild(svg);
let polyline = svg_polyline('20,40 20,80 60,80 60,40');
let polygon = svg_polygon('40,20 80,20 80,60 60,60 60,40 40,40');
let polyline = svg_polyline('20,40 20,80 60,80 60,40 20,40');
let polygon = svg_polygon('40,20 80,20 80,60 60,60 60,40 40,40 40,20');
svg.append(polygon, polyline);
return result;
}
Expand Down

0 comments on commit 5e14766

Please sign in to comment.