mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
feat: add ctx.editor.setValue method
This commit is contained in:
@@ -194,18 +194,13 @@ export function getValue () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace text value.
|
||||
* @param search
|
||||
* @param val
|
||||
* @param replaceAll
|
||||
* Set text value to editor
|
||||
* @param text
|
||||
*/
|
||||
export function replaceValue (search: string | RegExp, val: string, replaceAll = true) {
|
||||
const editor = getEditor()
|
||||
export function setValue (text: string) {
|
||||
const model = editor.getModel()
|
||||
const maxLine = model!.getLineCount()
|
||||
const endLineLength = model!.getLineLength(maxLine)
|
||||
const content = model!.getValue()
|
||||
const text = replaceAll ? content.replaceAll(search, val) : content.replace(search, val)
|
||||
|
||||
editor.executeEdits('', [
|
||||
{
|
||||
@@ -217,6 +212,20 @@ export function replaceValue (search: string | RegExp, val: string, replaceAll =
|
||||
getEditor().focus()
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace text value.
|
||||
* @param search
|
||||
* @param val
|
||||
* @param replaceAll
|
||||
*/
|
||||
export function replaceValue (search: string | RegExp, val: string, replaceAll = true) {
|
||||
const editor = getEditor()
|
||||
const model = editor.getModel()
|
||||
const content = model!.getValue()
|
||||
const text = replaceAll ? content.replaceAll(search, val) : content.replace(search, val)
|
||||
setValue(text)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get editor selection.
|
||||
* @returns
|
||||
|
||||
Reference in New Issue
Block a user