update: codeblock select left & right

This commit is contained in:
yanmao 2022-01-07 15:55:30 +08:00
parent 387991b1cc
commit 0233d30edd
6 changed files with 29 additions and 4 deletions

View File

@ -232,6 +232,17 @@ class CodeBlockEditor implements CodeBlockEditorInterface {
this.codeMirror.focus();
}
select(start: boolean = true) {
if (!this.codeMirror) return;
this.codeMirror.focus();
if (!start) {
const line = this.codeMirror.lineCount() - 1;
const content = this.codeMirror.getLine(line);
this.codeMirror.setSelection({ line, ch: content.length });
} else {
this.codeMirror.setSelection({ line: 0, ch: 0 });
}
}
/**
* runmode addon
*

View File

@ -232,7 +232,7 @@ class CodeBlcok<V extends CodeBlockValue = CodeBlockValue> extends Card<V> {
onSelectLeft(event: KeyboardEvent) {
if (!this.codeEditor) return;
event.preventDefault();
this.codeEditor.focus();
this.codeEditor.select(false);
this.activate(true);
this.toolbarModel?.show();
}
@ -240,7 +240,7 @@ class CodeBlcok<V extends CodeBlockValue = CodeBlockValue> extends Card<V> {
onSelectRight(event: KeyboardEvent) {
if (!this.codeEditor) return;
event.preventDefault();
this.codeEditor.focus();
this.codeEditor.select(true);
this.activate(true);
this.toolbarModel?.show();
}

View File

@ -31,6 +31,7 @@ export interface CodeBlockEditorInterface {
render(mode: string, value: string, options?: EditorConfiguration): void;
save(): void;
focus(): void;
select(start?: boolean): void;
/**
* runmode addon
*

View File

@ -233,6 +233,18 @@ class CodeBlockEditor implements CodeBlockEditorInterface {
this.codeMirror.focus();
}
select(start: boolean = true) {
if (!this.codeMirror) return;
this.codeMirror.focus();
if (!start) {
const line = this.codeMirror.lineCount() - 1;
const content = this.codeMirror.getLine(line);
this.codeMirror.setSelection({ line, ch: content.length });
} else {
this.codeMirror.setSelection({ line: 0, ch: 0 });
}
}
/**
* runmode addon
*

View File

@ -229,7 +229,7 @@ class CodeBlcok<V extends CodeBlockValue = CodeBlockValue> extends Card<V> {
onSelectLeft(event: KeyboardEvent) {
if (!this.codeEditor) return;
event.preventDefault();
this.codeEditor.focus();
this.codeEditor.select(false);
this.activate(true);
this.toolbarModel?.show();
}
@ -237,7 +237,7 @@ class CodeBlcok<V extends CodeBlockValue = CodeBlockValue> extends Card<V> {
onSelectRight(event: KeyboardEvent) {
if (!this.codeEditor) return;
event.preventDefault();
this.codeEditor.focus();
this.codeEditor.select(true);
this.activate(true);
this.toolbarModel?.show();
}

View File

@ -31,6 +31,7 @@ export interface CodeBlockEditorInterface {
render(mode: string, value: string, options?: EditorConfiguration): void;
save(): void;
focus(): void;
select(start?: boolean): void;
/**
* runmode addon
*