Addressed Telescope TODO; enhanced Telescope search
This commit is contained in:
4
TODO.md
4
TODO.md
@@ -1,6 +1,7 @@
|
||||
___
|
||||
### Add
|
||||
1. Add Godot LSP Client
|
||||
1. Add TreeSitter
|
||||
1. Add Collapsable code blocks
|
||||
1. Add Plugin to <Shift\><Ctrl\>| and <Ctrl\>| to split views up, down, left, right
|
||||
1. Add <Ctrl\>i to **lsp_manager** to list who implements xyz
|
||||
@@ -9,10 +10,9 @@ ___
|
||||
### Change
|
||||
1. Make **telescope** plugin a generic base to allow query mode additions through plugins
|
||||
1. Make **lsp_manager** hard coded values configurable, plus add fields to UI
|
||||
|
||||
___
|
||||
### Fix
|
||||
- Fix **telescope** search selection when items hidden such that
|
||||
hidden items don't get selected on up/down key
|
||||
- Fix to make acive tab on **tabs_bar** scroll to center
|
||||
- Fix **file_state_watcher** to prompt refrsh if external changes applied
|
||||
- Fix on lsp client unload to close files lsp side and unload server endpoint
|
||||
|
||||
@@ -45,6 +45,7 @@ class ListBox(Gtk.ListBox):
|
||||
|
||||
def _row_activated(self, list_box, row = None):
|
||||
row = self.get_selected_row()
|
||||
if not row: return
|
||||
file = row.get_children()[0].file
|
||||
|
||||
event = Event_Factory.create_event(
|
||||
@@ -70,25 +71,63 @@ class ListBox(Gtk.ListBox):
|
||||
|
||||
def search_changed(self, entry):
|
||||
self.search_buffer_names(entry)
|
||||
|
||||
for row in self.get_children():
|
||||
if not row.is_visible(): continue
|
||||
self.select_row(row)
|
||||
break
|
||||
|
||||
def fuzzy_score(self, query, text):
|
||||
query = query.lower()
|
||||
text = text.lower()
|
||||
score = 0
|
||||
q_idx = 0
|
||||
|
||||
for char in text:
|
||||
if q_idx < len(query) and char == query[q_idx]:
|
||||
score += 1
|
||||
q_idx += 1
|
||||
|
||||
return score if q_idx == len(query) else 0
|
||||
|
||||
|
||||
def search_buffer_names(self, entry):
|
||||
text = entry.get_text()
|
||||
if not text:
|
||||
for row in self.get_children():
|
||||
row.show()
|
||||
|
||||
return
|
||||
query = entry.get_text().lower()
|
||||
rows = []
|
||||
|
||||
for row in self.get_children():
|
||||
child = row.get_children()[0]
|
||||
label_text = child.get_label()
|
||||
score = self.fuzzy_score(query, label_text) if query else 1
|
||||
child.label_text = label_text if not hasattr(child, "label_text") else child.label_text
|
||||
|
||||
row.show() \
|
||||
if text in child.get_label() else \
|
||||
rows.append((score, row, child, label_text))
|
||||
|
||||
rows.sort(key = lambda x: x[0], reverse = True)
|
||||
for score, row, child, label_text in rows:
|
||||
if query and score > 0:
|
||||
highlighted = self.highlight_match(label_text, query)
|
||||
child.set_markup(highlighted)
|
||||
row.show()
|
||||
elif not query:
|
||||
child.set_label(child.label_text)
|
||||
row.show()
|
||||
else:
|
||||
row.hide()
|
||||
|
||||
def highlight_match(self, text, query):
|
||||
i = 0
|
||||
result = ""
|
||||
|
||||
for char in text:
|
||||
if i < len(query) and char.lower() == query[i].lower():
|
||||
result += f"<b><i><u>{char}</u></i></b>"
|
||||
i += 1
|
||||
else:
|
||||
result += char
|
||||
|
||||
return result
|
||||
|
||||
def activate_row(self):
|
||||
self._row_activated(self)
|
||||
|
||||
@@ -97,29 +136,43 @@ class ListBox(Gtk.ListBox):
|
||||
|
||||
def move_row_selection_up(self):
|
||||
row = self.get_selected_row()
|
||||
next_row = self.get_row_at_index(row.get_index() - 1)
|
||||
if not row: return
|
||||
|
||||
if not next_row:
|
||||
next_row = self.get_row_at_index(
|
||||
len( self.get_children() ) - 1
|
||||
)
|
||||
rows = [r for r in self.get_children() if r.is_visible()]
|
||||
if not rows: return
|
||||
|
||||
self.select_row(next_row)
|
||||
try:
|
||||
idx = rows.index(row)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
next_idx = (idx - 1) % len(rows)
|
||||
self.select_row(rows[next_idx])
|
||||
|
||||
def move_row_selection_down(self):
|
||||
row = self.get_selected_row()
|
||||
next_row = self.get_row_at_index(row.get_index() + 1)
|
||||
if not row: return
|
||||
|
||||
if not next_row:
|
||||
next_row = self.get_row_at_index(0)
|
||||
rows = [r for r in self.get_children() if r.is_visible()]
|
||||
if not rows: return
|
||||
|
||||
self.select_row(next_row)
|
||||
try:
|
||||
idx = rows.index(row)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
next_idx = (idx + 1) % len(rows)
|
||||
self.select_row(rows[next_idx])
|
||||
|
||||
def add_row(self, file):
|
||||
row = Gtk.ListBoxRow()
|
||||
label = Gtk.Label(label = file.fname)
|
||||
label.file = file
|
||||
label.show()
|
||||
self.add(label)
|
||||
|
||||
row.add(label)
|
||||
row.show_all()
|
||||
|
||||
self.add(row)
|
||||
|
||||
def remove_row(self, event):
|
||||
for row in self.get_children():
|
||||
|
||||
BIN
src/newton.zip
Normal file
BIN
src/newton.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user