update: codeblock select left & right
This commit is contained in:
parent
387991b1cc
commit
0233d30edd
|
@ -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
|
||||
* 支持行号需要考虑复制粘贴问题
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* 支持行号需要考虑复制粘贴问题
|
||||
|
|
|
@ -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
|
||||
* 支持行号需要考虑复制粘贴问题
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* 支持行号需要考虑复制粘贴问题
|
||||
|
|
Loading…
Reference in New Issue