Skip to content

Commit

Permalink
Added setLocationList to app interface, added function for setting lo…
Browse files Browse the repository at this point in the history
…cation list from current selector popup
  • Loading branch information
Nimaoth committed Apr 30, 2024
1 parent bb0145d commit 63003c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Binary file modified config/absytree_config_wasm.wasm
Binary file not shown.
3 changes: 2 additions & 1 deletion config/default_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ proc loadDefaultKeybindings*(clearExisting: bool = false) =
addCommand "popup.selector", "<C-n>", "next"
addCommand "popup.selector", "<C-u>", "prev-x"
addCommand "popup.selector", "<C-d>", "next-x"
addCommand "popup.selector", "<C-l>", "send-to-location-list"
addCommandBlock "popup.selector", "<C-l>":
setLocationListFromCurrentPopup()

addCommand "editor", "<C-n>", "goto-prev-location"
addCommand "editor", "<C-t>", "goto-next-location"
Expand Down
9 changes: 9 additions & 0 deletions scripting/editor_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import scripting_api, misc/myjsonutils
## This file is auto generated, don't modify.


proc editor_setLocationListFromCurrentPopup_void_App_wasm(arg: cstring): cstring {.
importc.}
proc setLocationListFromCurrentPopup*() =
var argsJson = newJArray()
let argsJsonString = $argsJson
let res {.used.} = editor_setLocationListFromCurrentPopup_void_App_wasm(
argsJsonString.cstring)


proc editor_getBackend_Backend_App_wasm(arg: cstring): cstring {.importc.}
proc getBackend*(): Backend =
var argsJson = newJArray()
Expand Down
18 changes: 18 additions & 0 deletions src/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ proc openSymbolsPopup*(self: App, symbols: seq[Symbol], handleItemSelected: proc
proc help*(self: App, about: string = "")
proc getAllDocuments*(self: App): seq[Document]
proc setHandleInputs*(self: App, context: string, value: bool)
proc setLocationList*(self: App, list: seq[SelectorItem])

implTrait AppInterface, App:
proc platform*(self: App): Platform = self.platform
Expand Down Expand Up @@ -262,6 +263,7 @@ implTrait AppInterface, App:
popPopup(void, App, Popup)
openSymbolsPopup(void, App, seq[Symbol], proc(symbol: Symbol), proc(symbol: Symbol), proc())
getAllDocuments(seq[Document], App)
setLocationList(void, App, seq[SelectorItem])

type
AppLogger* = ref object of Logger
Expand Down Expand Up @@ -1087,6 +1089,22 @@ proc getEditor(): Option[App] =
static:
addInjector(App, getEditor)

proc setLocationListFromCurrentPopup*(self: App) {.expose("editor").} =
if self.popups.len == 0:
return

let popup = block:
let popup = self.popups[self.popups.high]
if not (popup of SelectorPopup):
log lvlError, &"Not a selector popup"
return
popup.SelectorPopup

if popup.textEditor.isNil or popup.completions.len == 0:
return

self.setLocationList(popup.completions)

proc getBackend*(self: App): Backend {.expose("editor").} =
return self.backend

Expand Down
1 change: 1 addition & 0 deletions src/app_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ traitRef AppInterface:
method getEditorForId*(self: AppInterface, id: EditorId): Option[DocumentEditor]
method getPopupForId*(self: AppInterface, id: EditorId): Option[Popup]
method createSelectorPopup*(self: AppInterface): Popup
method setLocationList*(self: AppInterface, list: seq[SelectorItem])
method pushSelectorPopup*(self: AppInterface, popup: SelectorPopupBuilder): ISelectorPopup
method pushPopup*(self: AppInterface, popup: Popup)
method popPopup*(self: AppInterface, popup: Popup)
Expand Down

0 comments on commit 63003c6

Please sign in to comment.