mirror of https://codeberg.org/cage/tinmop/
- fixed searching in links or gemini pages: searching starts from the first row.
This commit is contained in:
parent
f6556fd4ff
commit
3ca18e1fd9
|
@ -245,22 +245,38 @@ this exact quantity wold go beyond the length or rows or zero."
|
|||
actual-amount)
|
||||
0)))
|
||||
|
||||
(defun prepare-new-search (window)
|
||||
(when (<= (line-oriented-window:row-selected-index window)
|
||||
0)
|
||||
(setf (line-oriented-window:row-selected-index window) -1)))
|
||||
|
||||
(defun cleanup-after-search (window)
|
||||
(when (< (line-oriented-window:row-selected-index window)
|
||||
0)
|
||||
(setf (line-oriented-window:row-selected-index window) 0)))
|
||||
|
||||
(defmethod search-row ((object row-oriented-widget) regex &key (redraw t))
|
||||
(handler-case
|
||||
(with-accessors ((row-selected-index row-selected-index)) object
|
||||
(when-let* ((scanner (create-scanner regex :case-insensitive-mode t))
|
||||
(position-found (position-if (lambda (a)
|
||||
(if (selectedp a)
|
||||
(scan scanner (selected-text a))
|
||||
(scan scanner (normal-text a))))
|
||||
(safe-subseq (rows object)
|
||||
(1+ row-selected-index)))))
|
||||
(unselect-all object)
|
||||
(select-row object (+ 1 row-selected-index position-found))
|
||||
(when redraw
|
||||
(draw object))
|
||||
position-found))
|
||||
(let* ((scanner (create-scanner regex :case-insensitive-mode t))
|
||||
(position-found (position-if (lambda (a)
|
||||
(if (selectedp a)
|
||||
(scan scanner (selected-text a))
|
||||
(scan scanner (normal-text a))))
|
||||
(safe-subseq (rows object)
|
||||
(1+ row-selected-index)))))
|
||||
(if position-found
|
||||
(progn
|
||||
(unselect-all object)
|
||||
(select-row object (+ 1 row-selected-index position-found))
|
||||
(when redraw
|
||||
(draw object))
|
||||
position-found)
|
||||
(progn
|
||||
(line-oriented-window:cleanup-after-search object)
|
||||
nil))))
|
||||
(error ()
|
||||
(line-oriented-window:cleanup-after-search object)
|
||||
(ui:error-message (_ "Invalid regular expression")))))
|
||||
|
||||
(defclass simple-line-navigation-window (wrapper-window row-oriented-widget border-window)
|
||||
|
|
|
@ -293,30 +293,32 @@
|
|||
:start (min (1+ row-selected-index)
|
||||
(length rows))))
|
||||
(replacements-strings ()))
|
||||
(when line-found
|
||||
(row-move object (- line-found row-selected-index))
|
||||
(draw object)
|
||||
(multiple-value-bind (first-window-line-simple first-window-line-complex)
|
||||
(first-line->string object)
|
||||
(labels ((calc-highlight (&optional (start-scan 0))
|
||||
(multiple-value-bind (start end)
|
||||
(scan regex first-window-line-simple :start start-scan)
|
||||
(when start
|
||||
(let* ((mask (make-tui-string (subseq first-window-line-simple
|
||||
start end)
|
||||
:fgcolor (win-bgcolor object)
|
||||
:bgcolor (win-fgcolor object)))
|
||||
(prefix (tui-string-subseq first-window-line-complex
|
||||
0
|
||||
start))
|
||||
(new-prefix (cat-tui-string prefix mask)))
|
||||
(push new-prefix replacements-strings)
|
||||
(calc-highlight end)))))
|
||||
(highlight ()
|
||||
(loop for replacement in replacements-strings do
|
||||
(print-text object replacement 1 1))))
|
||||
(calc-highlight)
|
||||
(highlight)))))))
|
||||
(if line-found
|
||||
(progn
|
||||
(row-move object (- line-found row-selected-index))
|
||||
(draw object)
|
||||
(multiple-value-bind (first-window-line-simple first-window-line-complex)
|
||||
(first-line->string object)
|
||||
(labels ((calc-highlight (&optional (start-scan 0))
|
||||
(multiple-value-bind (start end)
|
||||
(scan regex first-window-line-simple :start start-scan)
|
||||
(when start
|
||||
(let* ((mask (make-tui-string (subseq first-window-line-simple
|
||||
start end)
|
||||
:fgcolor (win-bgcolor object)
|
||||
:bgcolor (win-fgcolor object)))
|
||||
(prefix (tui-string-subseq first-window-line-complex
|
||||
0
|
||||
start))
|
||||
(new-prefix (cat-tui-string prefix mask)))
|
||||
(push new-prefix replacements-strings)
|
||||
(calc-highlight end)))))
|
||||
(highlight ()
|
||||
(loop for replacement in replacements-strings do
|
||||
(print-text object replacement 1 1))))
|
||||
(calc-highlight)
|
||||
(highlight))))
|
||||
(line-oriented-window:cleanup-after-search object)))))
|
||||
|
||||
(defun init ()
|
||||
(let* ((low-level-window (make-croatoan-window :enable-function-keys t)))
|
||||
|
|
|
@ -100,23 +100,6 @@
|
|||
:initarg :links
|
||||
:accessor links)))
|
||||
|
||||
(defmethod search-row ((object open-links-window) regex &key (redraw t))
|
||||
(handler-case
|
||||
(with-accessors ((row-selected-index row-selected-index)) object
|
||||
(when-let* ((scanner (create-scanner regex :case-insensitive-mode t))
|
||||
(position-found (position-if (lambda (a)
|
||||
(if (selectedp a)
|
||||
(scan scanner (selected-text a))
|
||||
(scan scanner (normal-text a))))
|
||||
(safe-subseq (rows object)
|
||||
row-selected-index))))
|
||||
(unselect-all object)
|
||||
(select-row object position-found)
|
||||
(when redraw
|
||||
(draw object))))
|
||||
(error ()
|
||||
(ui:error-message (_ "Invalid regular expression")))))
|
||||
|
||||
(defclass open-gemini-document-link-window (focus-marked-window
|
||||
simple-line-navigation-window
|
||||
title-window
|
||||
|
@ -196,12 +179,15 @@
|
|||
(safe-subseq (links object)
|
||||
(1+ row-selected-index)))))
|
||||
(call-next-method) ; search in urls
|
||||
(when position-header ; but if an header has been found, it wins
|
||||
(unselect-all object)
|
||||
(select-row object (+ 1 saved-selected-index position-header))
|
||||
(when redraw
|
||||
(draw object)))))
|
||||
(if position-header ; but if an header has been found, it wins
|
||||
(progn
|
||||
(unselect-all object)
|
||||
(select-row object (+ 1 saved-selected-index position-header))
|
||||
(when redraw
|
||||
(draw object)))
|
||||
(line-oriented-window:cleanup-after-search object))))
|
||||
(error ()
|
||||
(line-oriented-window:cleanup-after-search object)
|
||||
(ui:error-message (_ "Invalid regular expression")))))
|
||||
|
||||
(defun init-gemini-links (links)
|
||||
|
|
|
@ -1820,7 +1820,9 @@
|
|||
:selected-line-bg
|
||||
:selected-line-fg
|
||||
:resync-rows-db
|
||||
:make-blocking-list-dialog-window))
|
||||
:make-blocking-list-dialog-window
|
||||
:prepare-new-search
|
||||
:cleanup-after-search))
|
||||
|
||||
(defpackage :message-rendering-utils
|
||||
(:use
|
||||
|
|
|
@ -435,8 +435,9 @@
|
|||
(let ((regexp (payload object)))
|
||||
(when (text-utils:string-not-empty-p regexp)
|
||||
(handler-case
|
||||
(let ((scanner (cl-ppcre:create-scanner regexp :case-insensitive-mode t)))
|
||||
(message-window:search-regex specials:*message-window* scanner))
|
||||
(let ((scanner (cl-ppcre:create-scanner regexp :case-insensitive-mode t))
|
||||
(win specials:*message-window*))
|
||||
(message-window:search-regex win scanner))
|
||||
(cl-ppcre:ppcre-syntax-error ()
|
||||
(ui:error-message (_ "Invalid regular expression")))))))
|
||||
|
||||
|
|
|
@ -354,7 +354,9 @@ Metadata includes:
|
|||
"Search regular expression in message"
|
||||
(flet ((on-input-complete (regex)
|
||||
(let ((event (make-instance 'search-regex-message-content-event
|
||||
:payload regex)))
|
||||
:payload regex))
|
||||
(win specials:*message-window*))
|
||||
(line-oriented-window:prepare-new-search win)
|
||||
(push-event event))))
|
||||
(ask-string-input #'on-input-complete :prompt (_ "Search key: "))))
|
||||
|
||||
|
@ -1125,6 +1127,7 @@ Force the checking for new message in the thread the selected message belong."
|
|||
(let ((event (make-instance 'search-link-event
|
||||
:window window
|
||||
:regex regex)))
|
||||
(line-oriented-window:prepare-new-search window)
|
||||
(push-event event)))))
|
||||
(ask-string-input #'on-input-complete
|
||||
:prompt (_ "Search key: ")
|
||||
|
|
Loading…
Reference in New Issue