diff --git a/config/wasm/harpoon.wasm b/config/wasm/harpoon.wasm index 30c75959..09425fbf 100644 Binary files a/config/wasm/harpoon.wasm and b/config/wasm/harpoon.wasm differ diff --git a/config/wasm/keybindings_plugin.wasm b/config/wasm/keybindings_plugin.wasm index dd002343..27a2a41e 100644 Binary files a/config/wasm/keybindings_plugin.wasm and b/config/wasm/keybindings_plugin.wasm differ diff --git a/config/wasm/vscode_config_plugin.wasm b/config/wasm/vscode_config_plugin.wasm index 2a0abc89..91e6adab 100644 Binary files a/config/wasm/vscode_config_plugin.wasm and b/config/wasm/vscode_config_plugin.wasm differ diff --git a/scripting/editor_api_wasm.nim b/scripting/editor_api_wasm.nim index f58f1d84..8609db02 100644 --- a/scripting/editor_api_wasm.nim +++ b/scripting/editor_api_wasm.nim @@ -1129,91 +1129,6 @@ proc scriptInsertTextInto*(editorId: EditorId; text: string) {.gcsafe, argsJsonString.cstring) -proc editor_scriptTextEditorSelection_Selection_EditorId_wasm(arg: cstring): cstring {. - importc.} -proc scriptTextEditorSelection*(editorId: EditorId): Selection {.gcsafe, - raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptTextEditorSelection_Selection_EditorId_wasm( - argsJsonString.cstring) - try: - result = parseJson($res).jsonTo(typeof(result)) - except: - raiseAssert(getCurrentExceptionMsg()) - - -proc editor_scriptSetTextEditorSelection_void_EditorId_Selection_wasm( - arg: cstring): cstring {.importc.} -proc scriptSetTextEditorSelection*(editorId: EditorId; selection: Selection) {. - gcsafe, raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - argsJson.add selection.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptSetTextEditorSelection_void_EditorId_Selection_wasm( - argsJsonString.cstring) - - -proc editor_scriptTextEditorSelections_seq_Selection_EditorId_wasm(arg: cstring): cstring {. - importc.} -proc scriptTextEditorSelections*(editorId: EditorId): seq[Selection] {.gcsafe, - raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptTextEditorSelections_seq_Selection_EditorId_wasm( - argsJsonString.cstring) - try: - result = parseJson($res).jsonTo(typeof(result)) - except: - raiseAssert(getCurrentExceptionMsg()) - - -proc editor_scriptSetTextEditorSelections_void_EditorId_seq_Selection_wasm( - arg: cstring): cstring {.importc.} -proc scriptSetTextEditorSelections*(editorId: EditorId; - selections: seq[Selection]) {.gcsafe, - raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - argsJson.add selections.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptSetTextEditorSelections_void_EditorId_seq_Selection_wasm( - argsJsonString.cstring) - - -proc editor_scriptGetTextEditorLine_string_EditorId_int_wasm(arg: cstring): cstring {. - importc.} -proc scriptGetTextEditorLine*(editorId: EditorId; line: int): string {.gcsafe, - raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - argsJson.add line.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptGetTextEditorLine_string_EditorId_int_wasm( - argsJsonString.cstring) - try: - result = parseJson($res).jsonTo(typeof(result)) - except: - raiseAssert(getCurrentExceptionMsg()) - - -proc editor_scriptGetTextEditorLineCount_int_EditorId_wasm(arg: cstring): cstring {. - importc.} -proc scriptGetTextEditorLineCount*(editorId: EditorId): int {.gcsafe, raises: [].} = - var argsJson = newJArray() - argsJson.add editorId.toJson() - let argsJsonString = $argsJson - let res {.used.} = editor_scriptGetTextEditorLineCount_int_EditorId_wasm( - argsJsonString.cstring) - try: - result = parseJson($res).jsonTo(typeof(result)) - except: - raiseAssert(getCurrentExceptionMsg()) - - proc editor_setSessionDataJson_void_App_string_JsonNode_bool_wasm(arg: cstring): cstring {. importc.} proc setSessionDataJson*(path: string; value: JsonNode; override: bool = true) {. diff --git a/scripting/editor_text_api_wasm.nim b/scripting/editor_text_api_wasm.nim index 192b9d96..38543178 100644 --- a/scripting/editor_text_api_wasm.nim +++ b/scripting/editor_text_api_wasm.nim @@ -462,6 +462,21 @@ proc getText*(self: TextDocumentEditor; selection: Selection; raiseAssert(getCurrentExceptionMsg()) +proc editor_text_getLine_string_TextDocumentEditor_int_wasm(arg: cstring): cstring {. + importc.} +proc getLine*(self: TextDocumentEditor; line: int): string {.gcsafe, raises: [].} = + var argsJson = newJArray() + argsJson.add self.toJson() + argsJson.add line.toJson() + let argsJsonString = $argsJson + let res {.used.} = editor_text_getLine_string_TextDocumentEditor_int_wasm( + argsJsonString.cstring) + try: + result = parseJson($res).jsonTo(typeof(result)) + except: + raiseAssert(getCurrentExceptionMsg()) + + proc editor_text_insert_seq_Selection_TextDocumentEditor_seq_Selection_string_bool_bool_wasm( arg: cstring): cstring {.importc.} proc insert*(self: TextDocumentEditor; selections: seq[Selection]; text: string; @@ -2155,6 +2170,20 @@ proc getSelection*(self: TextDocumentEditor): Selection {.gcsafe, raises: [].} = raiseAssert(getCurrentExceptionMsg()) +proc editor_text_getSelections_Selections_TextDocumentEditor_wasm(arg: cstring): cstring {. + importc.} +proc getSelections*(self: TextDocumentEditor): Selections {.gcsafe, raises: [].} = + var argsJson = newJArray() + argsJson.add self.toJson() + let argsJsonString = $argsJson + let res {.used.} = editor_text_getSelections_Selections_TextDocumentEditor_wasm( + argsJsonString.cstring) + try: + result = parseJson($res).jsonTo(typeof(result)) + except: + raiseAssert(getCurrentExceptionMsg()) + + proc editor_text_setSelection_void_TextDocumentEditor_Selection_wasm( arg: cstring): cstring {.importc.} proc setSelection*(self: TextDocumentEditor; selection: Selection) {.gcsafe, @@ -2167,6 +2196,18 @@ proc setSelection*(self: TextDocumentEditor; selection: Selection) {.gcsafe, argsJsonString.cstring) +proc editor_text_setSelections_void_TextDocumentEditor_Selections_wasm( + arg: cstring): cstring {.importc.} +proc setSelections*(self: TextDocumentEditor; selections: Selections) {.gcsafe, + raises: [].} = + var argsJson = newJArray() + argsJson.add self.toJson() + argsJson.add selections.toJson() + let argsJsonString = $argsJson + let res {.used.} = editor_text_setSelections_void_TextDocumentEditor_Selections_wasm( + argsJsonString.cstring) + + proc editor_text_setTargetSelection_void_TextDocumentEditor_Selection_wasm( arg: cstring): cstring {.importc.} proc setTargetSelection*(self: TextDocumentEditor; selection: Selection) {. diff --git a/scripting/plugin_runtime.nim b/scripting/plugin_runtime.nim index 6b3ae1e7..851e81bd 100644 --- a/scripting/plugin_runtime.nim +++ b/scripting/plugin_runtime.nim @@ -115,30 +115,21 @@ proc runAction*(id: EditorId, action: string, arg: string = "") = proc runAction*(editor: TextDocumentEditor, action: string, arg: string = "") = scriptRunActionFor(editor.id, action, arg) -proc insertText*(editor: AnyDocumentEditor, text: string) = - scriptInsertTextInto(editor.id, text) - proc selection*(editor: TextDocumentEditor): Selection = return editor.getSelection() +proc selections*(editor: TextDocumentEditor): seq[Selection] = + return editor.getSelections() + proc `selection=`*(editor: TextDocumentEditor, selection: Selection) = editor.setSelection(selection) +proc `selections=`*(editor: TextDocumentEditor, selections: seq[Selection]) = + editor.setSelections(selections) + proc `targetSelection=`*(editor: TextDocumentEditor, selection: Selection) = editor.setTargetSelection(selection) -proc selections*(editor: TextDocumentEditor): seq[Selection] = - return scriptTextEditorSelections(editor.id) - -proc `selections=`*(editor: TextDocumentEditor, selection: seq[Selection]) = - scriptSetTextEditorSelections(editor.id, selection) - -proc getLine*(editor: TextDocumentEditor, line: int): string = - return scriptGetTextEditorLine(editor.id, line) - -proc getLineCount*(editor: TextDocumentEditor): int = - return scriptGetTextEditorLineCount(editor.id) - proc getOption*[T](path: string, default: T = T.default): T = try: let json: JsonNode = plugin_api.getOptionJson(path, newJNull()) diff --git a/src/app.nim b/src/app.nim index ae19be53..fe8af74e 100644 --- a/src/app.nim +++ b/src/app.nim @@ -197,8 +197,6 @@ type sessionFile*: string - gitIgnore: Globs - currentLocationListIndex: int finderItems: seq[FinderItem] previewer: Option[DisposableRef[Previewer]] @@ -1054,8 +1052,6 @@ proc newApp*(backend: api.Backend, platform: Platform, fs: Filesystem, services: self.currentView = 0 - self.gitIgnore = parseGlobs(self.fs.loadApplicationFile(".gitignore")) - assignEventHandler(self.eventHandler, self.getEventHandlerConfig("editor")): onAction: if self.handleAction(action, arg, record=true).isSome: @@ -3323,69 +3319,6 @@ proc scriptInsertTextInto*(editorId: EditorId, text: string) {.expose("editor"). if gEditor.getEditorForId(editorId).getSome(editor): discard editor.eventHandler.handleInput(text) -proc scriptTextEditorSelection*(editorId: EditorId): Selection {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return ((0, 0), (0, 0)) - defer: - gEditor.platform.requestRender() - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - let editor = TextDocumentEditor(editor) - return editor.selection - return ((0, 0), (0, 0)) - -proc scriptSetTextEditorSelection*(editorId: EditorId, selection: Selection) {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return - defer: - gEditor.platform.requestRender() - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - editor.TextDocumentEditor.selection = selection - -proc scriptTextEditorSelections*(editorId: EditorId): seq[Selection] {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return @[((0, 0), (0, 0))] - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - let editor = TextDocumentEditor(editor) - return editor.selections - return @[((0, 0), (0, 0))] - -proc scriptSetTextEditorSelections*(editorId: EditorId, selections: seq[Selection]) {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return - defer: - gEditor.platform.requestRender() - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - editor.TextDocumentEditor.selections = selections - -proc scriptGetTextEditorLine*(editorId: EditorId, line: int): string {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return "" - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - let editor = TextDocumentEditor(editor) - if line >= 0 and line < editor.document.numLines: - return $editor.document.getLine(line) - return "" - -proc scriptGetTextEditorLineCount*(editorId: EditorId): int {.expose("editor").} = - {.gcsafe.}: - if gEditor.isNil: - return 0 - if gEditor.getEditorForId(editorId).getSome(editor): - if editor of TextDocumentEditor: - let editor = TextDocumentEditor(editor) - return editor.document.numLines - return 0 - proc setSessionDataJson*(self: App, path: string, value: JsonNode, override: bool = true) {.expose("editor").} = if self.isNil or path.len == 0: return diff --git a/src/text/text_editor.nim b/src/text/text_editor.nim index 11ec9733..504be035 100644 --- a/src/text/text_editor.nim +++ b/src/text/text_editor.nim @@ -1086,6 +1086,9 @@ proc getText*(self: TextDocumentEditor, selection: Selection, inclusiveEnd: bool string {.expose("editor.text").} = return self.document.contentString(selection, inclusiveEnd) +proc getLine*(self: TextDocumentEditor, line: int): string {.expose("editor.text").} = + return $self.document.getLine(line) + proc insert*(self: TextDocumentEditor, selections: seq[Selection], text: string, notify: bool = true, record: bool = true): seq[Selection] {.expose("editor.text").} = return self.document.edit(selections, self.selections, [text], notify, record) @@ -3183,9 +3186,15 @@ proc assignKeys*(self: TextDocumentEditor, cursors: openArray[Cursor]): seq[stri proc getSelection*(self: TextDocumentEditor): Selection {.expose("editor.text").} = self.selection +proc getSelections*(self: TextDocumentEditor): Selections {.expose("editor.text").} = + self.selections + proc setSelection*(self: TextDocumentEditor, selection: Selection) {.expose("editor.text").} = self.selection = selection +proc setSelections*(self: TextDocumentEditor, selections: Selections) {.expose("editor.text").} = + self.selections = selections + proc setTargetSelection*(self: TextDocumentEditor, selection: Selection) {.expose("editor.text").} = self.targetSelection = selection