Skip to content

Commit

Permalink
Merge pull request #31 from jtherrmann/master
Browse files Browse the repository at this point in the history
New config options, Tab and Shift+Tab for moving caret
  • Loading branch information
e3rd authored Nov 23, 2017
2 parents 4b485a2 + 768a71e commit d39a785
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ Much quicker than current Zim search.


### Working with & Feedback
Known to work on Ubuntu 17.04 Zim 0.67+, Ubuntu 15.10 Zim 0.65+, Win 7 Zim 0.63+.
(For **earlier version than Zim 0.66-** use an old commit from Mar 17, not the current version.)
Known to work on:

* Ubuntu 17.04 Zim 0.67+
* Ubuntu 15.10 Zim 0.65+
* Win 7 Zim 0.63+
* Debian 8.9 Zim 0.62-3, 0.65-4, 0.67-1

I'd be glad to hear from you if it's working either here in the issues or in the original bug https://bugs.launchpad.net/zim/+bug/1409626 .

### Installation
Expand Down
14 changes: 10 additions & 4 deletions instantsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class InstantsearchPlugin(PluginClass):
('ignore_subpages', 'bool', _("Ignore subpages (if ignored, search 'linux' would return page:linux but not page:linux:subpage (if in the subpage, there is no occurece of string 'linux')"), True),
('isWildcarded', 'bool', _("Append wildcards to the search string: *string*"), True),
('isCached', 'bool', _("Cache results of a search to be used in another search. (Till the end of zim process.)"), True),
('open_when_unique', 'bool', _('When only one page is found, open it automatically.'), True),
('position', 'choice', _('Popup position'), POSITION_RIGHT, (POSITION_RIGHT, POSITION_CENTER))
# T: plugin preference
)
Expand Down Expand Up @@ -102,10 +103,15 @@ def instantsearch(self):
self.title_match_char = self.plugin.preferences['title_match_char']
self.start_search_length = self.plugin.preferences['start_search_length']
self.keystroke_delay = self.plugin.preferences['keystroke_delay']
self.open_when_unique = self.plugin.preferences['open_when_unique']

# building quick title cache
def build(start = ""):
for s in self.window.ui.notebook.pages.list_pages(Path(start or ":")):
if hasattr(self.window.ui.notebook, 'pages'):
o = self.window.ui.notebook.pages
else: # for Zim 0.66-
o = self.window.ui.notebook.index
for s in o.list_pages(Path(start or ":")):
start2 = (start + ":" if start else "") + s.basename
self.cached_titles.append((start2, start2.lower()))
build(start2)
Expand Down Expand Up @@ -240,7 +246,7 @@ def startZimSearch(self):

def checkLast(self):
""" opens the page if there is only one option in the menu """
if len(self.state.menu) == 1:
if self.open_when_unique and len(self.state.menu) == 1:
self._open_page(Path(self.state.menu.keys()[0]), excludeFromHistory=False)
self.close()

Expand Down Expand Up @@ -331,11 +337,11 @@ def soutMenu(self, displayImmediately=False):
def move(self, widget, event):
""" Move caret up and down. Enter to confirm, Esc closes search."""
keyname = gtk.gdk.keyval_name(event.keyval)
if keyname == "Up":
if keyname == "Up" or keyname == "ISO_Left_Tab":
self.caret['pos'] -= 1
self.soutMenu(displayImmediately=False)

if keyname == "Down":
if keyname == "Down" or keyname == "Tab":
self.caret['pos'] += 1
self.soutMenu(displayImmediately=False)

Expand Down

0 comments on commit d39a785

Please sign in to comment.