Skip to content

Commit

Permalink
added goto next/prev error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Dec 15, 2023
1 parent a28ca64 commit 58f1848
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
Binary file modified config/absytree_config_wasm.wasm
Binary file not shown.
8 changes: 5 additions & 3 deletions config/keybindings_normal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ proc loadNormalKeybindings*() {.scriptActionWasmNims("load-normal-keybindings").
addModelCommand "", "<*C-g>P", "goto-prev-node-of-class", "ParameterDecl"
addModelCommand "", "<*C-g>i", "goto-next-node-of-class", "ThenCase"
addModelCommand "", "<*C-g>I", "goto-prev-node-of-class", "ThenCase"
addModelCommand "", "<*C-g>e", "goto-next-node-of-class", "ForLoop"
addModelCommand "", "<*C-g>E", "goto-prev-node-of-class", "ForLoop"
addModelCommand "", "<*C-g>o", "goto-next-node-of-class", "ForLoop"
addModelCommand "", "<*C-g>O", "goto-prev-node-of-class", "ForLoop"
addModelCommand "", "<*C-g>w", "goto-next-node-of-class", "WhileExpression"
addModelCommand "", "<*C-g>W", "goto-prev-node-of-class", "WhileExpression"
addModelCommand "", "<*C-g>R", "goto-prev-reference"
addModelCommand "", "<*C-g>r", "goto-next-reference"
addModelCommand "", "<*C-g>R", "goto-prev-reference"
addModelCommand "", "<*C-g>e", "goto-next-invalid-node"
addModelCommand "", "<*C-g>E", "goto-prev-invalid-node"

addCommand "editor.model", "<BACKSPACE>", "replace-left"
addCommand "editor.model", "<DELETE>", "replace-right"
Expand Down
6 changes: 6 additions & 0 deletions scripting/absytree_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ proc editor_model_gotoPrevReference_void_ModelDocumentEditor_impl*(
proc editor_model_gotoNextReference_void_ModelDocumentEditor_impl*(
self: ModelDocumentEditor) =
discard
proc editor_model_gotoPrevInvalidNode_void_ModelDocumentEditor_impl*(
self: ModelDocumentEditor) =
discard
proc editor_model_gotoNextInvalidNode_void_ModelDocumentEditor_impl*(
self: ModelDocumentEditor) =
discard
proc editor_model_gotoPrevNodeOfClass_void_ModelDocumentEditor_string_bool_impl*(
self: ModelDocumentEditor; className: string; select: bool = false) =
discard
Expand Down
4 changes: 4 additions & 0 deletions scripting/absytree_internal_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ proc editor_model_gotoPrevReference_void_ModelDocumentEditor_impl(
self: ModelDocumentEditor) {.importc.}
proc editor_model_gotoNextReference_void_ModelDocumentEditor_impl(
self: ModelDocumentEditor) {.importc.}
proc editor_model_gotoPrevInvalidNode_void_ModelDocumentEditor_impl(
self: ModelDocumentEditor) {.importc.}
proc editor_model_gotoNextInvalidNode_void_ModelDocumentEditor_impl(
self: ModelDocumentEditor) {.importc.}
proc editor_model_gotoPrevNodeOfClass_void_ModelDocumentEditor_string_bool_impl(
self: ModelDocumentEditor; className: string; select: bool = false) {.importc.}
proc editor_model_gotoNextNodeOfClass_void_ModelDocumentEditor_string_bool_impl(
Expand Down
4 changes: 4 additions & 0 deletions scripting/editor_model_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ proc gotoPrevReference*(self: ModelDocumentEditor) =
editor_model_gotoPrevReference_void_ModelDocumentEditor_impl(self)
proc gotoNextReference*(self: ModelDocumentEditor) =
editor_model_gotoNextReference_void_ModelDocumentEditor_impl(self)
proc gotoPrevInvalidNode*(self: ModelDocumentEditor) =
editor_model_gotoPrevInvalidNode_void_ModelDocumentEditor_impl(self)
proc gotoNextInvalidNode*(self: ModelDocumentEditor) =
editor_model_gotoNextInvalidNode_void_ModelDocumentEditor_impl(self)
proc gotoPrevNodeOfClass*(self: ModelDocumentEditor; className: string;
select: bool = false) =
editor_model_gotoPrevNodeOfClass_void_ModelDocumentEditor_string_bool_impl(
Expand Down
28 changes: 28 additions & 0 deletions scripting/editor_model_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ proc gotoNextReference*(self: ModelDocumentEditor) =
argsJsonString.cstring)


proc editor_model_gotoPrevInvalidNode_void_ModelDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc gotoPrevInvalidNode*(self: ModelDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when ModelDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_model_gotoPrevInvalidNode_void_ModelDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_model_gotoNextInvalidNode_void_ModelDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc gotoNextInvalidNode*(self: ModelDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when ModelDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_model_gotoNextInvalidNode_void_ModelDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_model_gotoPrevNodeOfClass_void_ModelDocumentEditor_string_bool_wasm(
arg: cstring): cstring {.importc.}
proc gotoPrevNodeOfClass*(self: ModelDocumentEditor; className: string;
Expand Down
38 changes: 38 additions & 0 deletions src/model_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,44 @@ proc gotoPrevReference*(self: ModelDocumentEditor) {.expose("editor.model").} =
proc gotoNextReference*(self: ModelDocumentEditor) {.expose("editor.model").} =
self.gotoNeighborReference(Right)

proc gotoInvalidNode*(self: ModelDocumentEditor, direction: Direction) =
if getTargetCell(self.cursor, false).getSome(cell):
let originalNode = cell.node

var nextCell = getNeighborLeafWhere(cell, self.nodeCellMap, direction, proc(c: Cell): bool =
if c == cell or c.node == originalNode or not isVisible(cell):
return false
discard self.document.ctx.validateNode(c.node)
if self.document.ctx.getDiagnostics(c.node.id).len > 0:
return true
return false
)

if nextCell.isNone: # wrap around
let endCell = if direction == Left: cell.rootPath.root.getLastLeaf(self.nodeCellMap) else: cell.rootPath.root.getFirstLeaf(self.nodeCellMap)
nextCell = getNeighborLeafWhere(endCell, self.nodeCellMap, direction, proc(c: Cell): bool =
if not isVisible(cell):
return false
if c == cell:
return true
discard self.document.ctx.validateNode(c.node)
if self.document.ctx.getDiagnostics(c.node.id).len > 0:
return true
return false
)

if nextCell.getSome(c):
self.cursor = self.nodeCellMap.toCursor(c, true)
# self.cursor = self.getFirstEditableCellOfNode(c.node).get
self.updateScrollOffset()
self.markDirty()

proc gotoPrevInvalidNode*(self: ModelDocumentEditor) {.expose("editor.model").} =
self.gotoInvalidNode(Left)

proc gotoNextInvalidNode*(self: ModelDocumentEditor) {.expose("editor.model").} =
self.gotoInvalidNode(Right)

proc gotoPrevNodeOfClass*(self: ModelDocumentEditor, className: string, select: bool = false) {.expose("editor.model").} =
log lvlInfo, fmt"gotoPrevNodeOfClass {className}"
if getTargetCell(self.cursor, false).getSome(cell):
Expand Down

0 comments on commit 58f1848

Please sign in to comment.