From 9187edf2383133b812e90be9c423c40a7dfa71ba Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Fri, 15 Mar 2019 16:34:26 -0500 Subject: [PATCH] Fuzzy open hotkey, window specific current doc, case-sensitive highlight --- feud.ini | 1 + plugins/server/file.nim | 49 +++++++++++++++++++++++++-------------- plugins/server/search.nim | 3 ++- plugins/server/window.nim | 20 ++++++++++++++++ 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/feud.ini b/feud.ini index 3ad8358..52840ba 100644 --- a/feud.ini +++ b/feud.ini @@ -6,6 +6,7 @@ hotkey ^k closeWindow hotkey ^+n newDoc hotkey ^o togglePopup open +hotkey ^+o togglePopup open -f hotkey ^s save hotkey ^+s togglePopup saveAs hotkey ^w close diff --git a/plugins/server/file.nim b/plugins/server/file.nim index cdd13fd..ff3bdbd 100644 --- a/plugins/server/file.nim +++ b/plugins/server/file.nim @@ -12,12 +12,22 @@ type cursor: int Docs = ref object - current: int doclist: seq[Doc] proc getDocs(plg: var Plugin): Docs = return getCtxData[Docs](plg) +proc getDocId(plg: var Plugin): int = + result = -1 + if plg.ctx.handleCommand(plg.ctx, "getDocId"): + try: + result = plg.ctx.cmdParam[0].parseInt() + except: + discard + +proc setDocId(plg: var Plugin, docid: int) = + discard plg.ctx.handleCommand(plg.ctx, &"setDocId {docid}") + proc findDocFromString(plg: var Plugin, srch: string): int = result = -1 var @@ -72,7 +82,7 @@ proc findDocFromParam(plg: var Plugin, param: string): int = result = if param.len == 0: - docs.current + plg.getDocId() else: plg.findDocFromString(param) @@ -88,17 +98,18 @@ proc findDocFromParam(plg: var Plugin, param: string): int = proc switchDoc(plg: var Plugin, docid: int) = var docs = plg.getDocs() + current = plg.getDocId() - if docid < 0 or docid > docs.doclist.len-1 or docid == docs.current: + if docid < 0 or docid > docs.doclist.len-1 or current < 0 or docid == current: return - docs.doclist[docs.current].cursor = plg.ctx.msg(plg.ctx, SCI_GETCURRENTPOS) - discard plg.ctx.msg(plg.ctx, SCI_ADDREFDOCUMENT, 0, docs.doclist[docs.current].docptr) + docs.doclist[current].cursor = plg.ctx.msg(plg.ctx, SCI_GETCURRENTPOS) + discard plg.ctx.msg(plg.ctx, SCI_ADDREFDOCUMENT, 0, docs.doclist[current].docptr) discard plg.ctx.msg(plg.ctx, SCI_SETDOCPOINTER, 0, docs.doclist[docid].docptr) discard plg.ctx.msg(plg.ctx, SCI_RELEASEDOCUMENT, 0, docs.doclist[docid].docptr) discard plg.ctx.msg(plg.ctx, SCI_GOTOPOS, docs.doclist[docid].cursor) - docs.current = docid + plg.setDocId(docid) discard plg.ctx.handleCommand(plg.ctx, &"setTitle {docid}: {docs.doclist[docid].path}") @@ -242,10 +253,11 @@ proc open(plg: var Plugin) {.feudCallback.} = proc save(plg: var Plugin) {.feudCallback.} = var docs = plg.getDocs() + current = plg.getDocId() - if docs.doclist.len != 0 and docs.current != 0: + if docs.doclist.len != 0 and current > 0: let - doc = docs.doclist[docs.current] + doc = docs.doclist[current] if doc.path == "New document": plg.ctx.notify(plg.ctx, &"Save new document using saveAs ") @@ -265,7 +277,7 @@ proc save(plg: var Plugin) {.feudCallback.} = f.close() plg.ctx.notify(plg.ctx, &"Saved {doc.path}") - discard plg.ctx.handleCommand(plg.ctx, &"setTitle {docs.current}: {doc.path}") + discard plg.ctx.handleCommand(plg.ctx, &"setTitle {current}: {doc.path}") except: plg.ctx.notify(plg.ctx, &"Failed to save {doc.path}") @@ -273,7 +285,7 @@ proc saveAs(plg: var Plugin) {.feudCallback.} = if plg.ctx.cmdParam.len != 0: var docs = plg.getDocs() - doc = docs.doclist[docs.current] + doc = docs.doclist[plg.getDocId()] doc.path = plg.ctx.cmdParam[0].expandFilename() @@ -300,16 +312,17 @@ proc close(plg: var Plugin) {.feudCallback.} = var docid = plg.findDocFromParam(param) + current = plg.getDocId() - if docid > 0: - if docid == docs.current: + if docid > 0 and current > -1: + if docid == current: if docid == docs.doclist.len-1: plg.switchDoc(docid-1) else: plg.switchDoc(docid+1) else: - if docid < docs.current: - docs.current -= 1 + if docid < current: + plg.setDocId(current-1) discard plg.ctx.msg(plg.ctx, SCI_RELEASEDOCUMENT, 0, docs.doclist[docid].docptr) docs.doclist.del(docid) @@ -325,7 +338,7 @@ proc closeAll(plg: var Plugin) {.feudCallback.} = proc reload(plg: var Plugin) {.feudCallback.} = var docs = plg.getDocs() - docid = docs.current + docid = plg.getDocId() if docid > 0: let @@ -341,7 +354,7 @@ proc next(plg: var Plugin) {.feudCallback.} = if docs.doclist.len != 1: var - docid = docs.current + docid = plg.getDocId() docid += 1 if docid == docs.doclist.len: docid = 0 @@ -354,7 +367,7 @@ proc prev(plg: var Plugin) {.feudCallback.} = if docs.doclist.len != 1: var - docid = docs.current + docid = plg.getDocId() docid -= 1 if docid < 0: docid = docs.doclist.len-1 @@ -375,4 +388,4 @@ feudPluginLoad: discard plg.ctx.msg(plg.ctx, SCI_SETDOCPOINTER, 0, notif.docptr, windowID=0) docs.doclist.add notif - docs.current = 0 + plg.setDocId(0) diff --git a/plugins/server/search.nim b/plugins/server/search.nim index 4663d78..b38343a 100644 --- a/plugins/server/search.nim +++ b/plugins/server/search.nim @@ -78,7 +78,7 @@ proc search(plg: var Plugin) {.feudCallback.} = discard plg.ctx.msg(plg.ctx, SCI_TARGETWHOLEDOCUMENT) discard plg.ctx.msg(plg.ctx, SCI_SETTARGETSTART, curpos+1) pos = plg.ctx.msg(plg.ctx, SCI_SEARCHINTARGET, search.needle.len, search.needle.cstring) - + if pos != -1: discard plg.ctx.msg(plg.ctx, SCI_GOTOPOS, pos) else: @@ -102,6 +102,7 @@ proc highlight(plg: var Plugin) {.feudCallback.} = pos = 0 while pos != -1: discard plg.ctx.msg(plg.ctx, SCI_TARGETWHOLEDOCUMENT) + discard plg.ctx.msg(plg.ctx, SCI_SETSEARCHFLAGS, SCFIND_MATCHCASE) discard plg.ctx.msg(plg.ctx, SCI_SETTARGETSTART, pos) pos = plg.ctx.msg(plg.ctx, SCI_SEARCHINTARGET, search.len, search.cstring) if pos != -1: diff --git a/plugins/server/window.nim b/plugins/server/window.nim index a395f4b..6c21885 100644 --- a/plugins/server/window.nim +++ b/plugins/server/window.nim @@ -479,6 +479,26 @@ proc execPopup(plg: var Plugin) = plg.addHistory() discard plg.ctx.handleCommand(plg.ctx, cmd) +proc getDocId(plg: var Plugin) {.feudCallback.} = + var + windows = plg.getWindows() + winid = windows.current + + plg.ctx.cmdParam = @[$(windows.editors[winid].docid)] + +proc setDocId(plg: var Plugin) {.feudCallback.} = + if plg.ctx.cmdParam.len != 0: + var + windows = plg.getWindows() + winid = windows.current + docid = -1 + + try: + docid = plg.ctx.cmdParam[0].parseInt() + windows.editors[winid].docid = docid + except: + discard + feudPluginDepends(["config"]) feudPluginLoad: