Skip to content

Commit

Permalink
feat: text editor
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Apr 4, 2024
1 parent 87f2316 commit 0b0bd78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/text/text_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class TextEditor {
constructor(private editor: Editor) {
this.textarea = document.createElement('input');
this.setStyle();
this.hide();
this.inactive();
this.bindEvent();
editor.containerElement.appendChild(this.textarea);
}
Expand All @@ -35,12 +35,12 @@ export class TextEditor {
private bindEvent() {
this.textarea.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
this.hide();
this.inactive();
}
});
this.textarea.addEventListener('blur', () => {
this.createTextGraph();
this.hide();
this.inactive();
});
}
private createTextGraph() {
Expand Down Expand Up @@ -72,7 +72,7 @@ export class TextEditor {
new AddGraphCmd('draw text', this.editor, [text]),
);
}
visible(x: number, y: number) {
active(x: number, y: number) {
this.x = x;
this.y = y;
const zoom = this.editor.zoomManager.getZoom();
Expand All @@ -90,7 +90,7 @@ export class TextEditor {

textarea.focus();
}
hide() {
inactive() {
this.textarea.style.display = 'none';
this.textarea.value = '';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tools/tool_draw_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DrawTextTool implements ITool {
const { x, y } = this.editor.getCursorXY(e);

// 让一个 input 元素出现在光标位置,然后输入内容回车。
this.editor.textEditor.visible(x, y);
this.editor.textEditor.active(x, y);
if (!this.editor.setting.get('keepToolSelectedAfterUse')) {
this.editor.toolManager.setActiveTool('select');
}
Expand Down

0 comments on commit 0b0bd78

Please sign in to comment.