From: Michael D. Lowis Date: Fri, 26 May 2017 13:00:42 +0000 (-0400) Subject: Added shortcuts for adding and jumping to bookmarks X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e45e5a62815be2dff235b41e5d5e10e0981c3d6f;p=projs%2Ftide.git Added shortcuts for adding and jumping to bookmarks --- diff --git a/TODO.md b/TODO.md index ded4f4f..94990bb 100644 --- a/TODO.md +++ b/TODO.md @@ -8,8 +8,6 @@ Up Next: var infoId = 'readerinfo'+reader.id; * rename to tide -* Ctrl+Shift+N to set a mark, Ctrl+N to jump to a mark -* Make Fn keys execute nth command in the tags buffers * Add a way to CD using a builtin * Ctrl+PageUp/Dn to move cursor by screenfuls * Ctrl+\ Shortcut to warp cursor to middle of current screen. @@ -22,6 +20,7 @@ Up Next: The Future: +* Make Fn keys execute nth command in the tags buffers * use transaction ids to only mark buffer dirty when it really is * refactor selection handling to buf.c to prepare for multiple selections. * 100% coverage with unit and unit-integration tests diff --git a/docs/xedit.1 b/docs/xedit.1 index 1e47a96..32ae155 100644 --- a/docs/xedit.1 +++ b/docs/xedit.1 @@ -220,6 +220,17 @@ Scroll the active region up by one screenful of text\. The cursor is not affecte \fBPageDn\fR Scroll the active region down by one screenful of text\. The cursor is not affected by this operation\. . +.SS "Bookmark Shortcuts" +\fBxedit\fR supports marking locations in a document to quickly jump to later\. This eases navigation between multiple locations in a large document\. +. +.TP +\fBCtrl+[0\-9]\fR +Jump to a bookmarked location\. +. +.TP +\fBCtrl+Alt+[0\-9]\fR +Save the cursor location as a bookmark +. .SS "Search Shortcuts" The shortcuts below allow the user to search for selected text or by context\. The direction of the search defaults to the forward direction with regard to the position in the file\. Each search follows the direction of the previous search unless the \fBShift\fR modifier is applied\. The \fBShift\fR modifier causes the current search operation to be applied in the opposite direction of the previous\. . @@ -270,6 +281,10 @@ Launch xtagpick(1) to select a tag from a ctags(1) generated index file\. \fBxed Lookup the selected symbol or symbol under the cursor in a ctags(1) generated index file\. Jump to the location of the definition if it exist in the current file\. Otherwise, a new instance of \fBxedit\fR will be launched with the target file and the cursor set to the line containing the definition\. . .TP +\fBCtrl+Shift+g\fR +Jump to the previous cursor location\. +. +.TP \fBCtrl+n\fR Open a new instance of \fBxedit\fR with no filename\. . diff --git a/docs/xedit.1.md b/docs/xedit.1.md index 71f4767..65c2007 100644 --- a/docs/xedit.1.md +++ b/docs/xedit.1.md @@ -250,6 +250,17 @@ position. Scroll the active region down by one screenful of text. The cursor is not affected by this operation. +### Bookmark Shortcuts + +`xedit` supports marking locations in a document to quickly jump to later. This +eases navigation between multiple locations in a large document. + +* `Ctrl+[0-9]`: + Jump to a bookmarked location. + +* `Ctrl+Alt+[0-9]`: + Save the cursor location as a bookmark + ### Search Shortcuts The shortcuts below allow the user to search for selected text or by context. diff --git a/inc/win.h b/inc/win.h index 77b464a..911746d 100644 --- a/inc/win.h +++ b/inc/win.h @@ -45,6 +45,7 @@ void win_dialog(char* name, void (*errfn)(char*)); void win_loop(void); void win_settext(WinRegion id, char* text); void win_setruler(size_t ruler); +Rune win_getkey(void); void win_setkeys(KeyBinding* bindings); void win_setmouse(MouseConfig* mconfig); void win_warpptr(WinRegion id); diff --git a/inc/x11.h b/inc/x11.h index 8fd3bcd..6137c6a 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -103,6 +103,7 @@ enum { ModNumLock = (1 << 4), ModScrollLock = (1 << 5), ModWindows = (1 << 6), + ModOneOrMore = (ModCtrl|ModAlt), ModAny = -1 }; diff --git a/lib/win.c b/lib/win.c index 8466683..8b9fe69 100644 --- a/lib/win.c +++ b/lib/win.c @@ -29,7 +29,8 @@ static XConfig Config = { }; static WinRegion Focused = EDIT; static Region Regions[NREGIONS] = {0}; -KeyBinding* Keys = NULL; +static Rune LastKey; +static KeyBinding* Keys = NULL; static void win_init(void (*errfn)(char*)) { for (int i = 0; i < SCROLL; i++) @@ -92,6 +93,10 @@ void win_setruler(size_t ruler) { Ruler = ruler; } +Rune win_getkey(void) { + return LastKey; +} + void win_setkeys(KeyBinding* bindings) { Keys = bindings; } @@ -229,14 +234,19 @@ static void onredraw(int width, int height) { } static void oninput(int mods, Rune key) { + LastKey = key; /* mask of modifiers we don't care about */ - mods = mods & (ModCtrl|ModAlt|ModShift); + mods = mods & (ModCtrl|ModShift|ModAlt); /* handle the proper line endings */ if (key == '\r') key = '\n'; /* search for a key binding entry */ uint32_t mkey = tolower(key); for (KeyBinding* bind = Keys; bind && bind->key; bind++) { - if ((mkey == bind->key) && (bind->mods == ModAny || bind->mods == mods)) { + bool match = (mkey == bind->key); + bool exact = (bind->mods == mods); + bool any = (bind->mods == ModAny); + bool oneplus = ((bind->mods == ModOneOrMore) && (mods & ModOneOrMore)); + if (match && (exact || oneplus || any)) { bind->action(); return; } diff --git a/xedit.c b/xedit.c index 28225e4..5d659a6 100644 --- a/xedit.c +++ b/xedit.c @@ -20,6 +20,7 @@ typedef struct { static Tag Builtins[]; static int SearchDir = DOWN; static char* SearchTerm = NULL; +static size_t Marks[10] = {0}; /* Tag/Cmd Execution ******************************************************************************/ @@ -379,10 +380,19 @@ static void newline(void) { view_insert(view, true, '\n'); } -void highlight(void) { +static void highlight(void) { view_selctx(win_view(FOCUSED)); } +static void jumpmark(void) { + int mark = (win_getkey() - '0'); + assert(mark < 10); + if (x11_keymodsset(ModAlt)) + Marks[mark] = win_view(FOCUSED)->selection.end; + else + view_jumpto(win_view(FOCUSED), false, Marks[mark]); +} + /* Main Routine ******************************************************************************/ static Tag Builtins[] = { @@ -440,23 +450,30 @@ static KeyBinding Bindings[] = { { ModAny, KEY_DELETE, delete }, { ModAny, KEY_BACKSPACE, backspace }, + /* Marks Handling */ + { ModOneOrMore, '0', jumpmark }, + { ModOneOrMore, '1', jumpmark }, + { ModOneOrMore, '2', jumpmark }, + { ModOneOrMore, '3', jumpmark }, + { ModOneOrMore, '4', jumpmark }, + { ModOneOrMore, '5', jumpmark }, + { ModOneOrMore, '6', jumpmark }, + { ModOneOrMore, '7', jumpmark }, + { ModOneOrMore, '8', jumpmark }, + { ModOneOrMore, '9', jumpmark }, + /* Implementation Specific */ { ModNone, KEY_ESCAPE, select_prev }, { ModCtrl, 't', change_focus }, { ModCtrl, 'q', quit }, { ModCtrl, 'h', highlight }, - { ModCtrl, 'f', search }, - { ModCtrl|ModShift, 'f', search }, - { ModCtrl|ModAlt, 'f', search }, - { ModCtrl|ModAlt|ModShift, 'f', search }, + { ModOneOrMore, 'f', search }, { ModCtrl, 'd', execute }, { ModCtrl, 'o', open_file }, { ModCtrl, 'p', pick_ctag }, - { ModCtrl, 'g', goto_ctag }, - { ModCtrl|ModShift, 'g', goto_ctag }, + { ModOneOrMore, 'g', goto_ctag }, { ModCtrl, 'n', new_win }, - { ModCtrl, '\n', newline }, - { ModCtrl|ModShift, '\n', newline }, + { ModOneOrMore, '\n', newline }, { ModCtrl, ' ', complete }, { 0, 0, 0 } };