1
0
Fork 0

- allowed complete local path even when using file scheme ('file://').

This commit is contained in:
cage 2023-04-07 13:05:36 +02:00
parent 2b19e708d9
commit 4ee09ae301
4 changed files with 34 additions and 18 deletions

View File

@ -222,6 +222,16 @@ list af all possible candidtae for completion."
(setf indices (loop for i in ordering collect (elt indices i)))
(values strings indices)))
(defun maybe-remove-file-scheme (maybe-file-scheme-iri)
(let ((parsed-as-iri (iri:iri-parse maybe-file-scheme-iri :null-on-error t)))
(if (and parsed-as-iri
(string= (uri:scheme parsed-as-iri) constants:+file-scheme+)
(and (text-utils:string-starts-with-p (text-utils:strcat constants:+file-scheme+
"://")
maybe-file-scheme-iri)))
(uri:path parsed-as-iri)
maybe-file-scheme-iri)))
(defun expand-iri-as-local-path-p (hint)
(or (text-utils:string-starts-with-p fs:*directory-sep* hint)
(text-utils:string-starts-with-p "." hint)
@ -229,24 +239,24 @@ list af all possible candidtae for completion."
(defun make-complete-gemini-iri-fn (prompt)
(lambda (hint)
(if (expand-iri-as-local-path-p hint)
(directory-complete hint)
(when-let ((bag (remove-duplicates (funcall #'db:history-prompt->values
prompt)
:test #'string=)))
(multiple-value-bind (matched-strings indices)
(uri-matcher hint bag)
(when matched-strings
(values matched-strings
nil ;for fuzzy search common prefix does
(let ((actual-hint (maybe-remove-file-scheme hint)))
(if (expand-iri-as-local-path-p actual-hint)
(directory-complete actual-hint)
(when-let ((bag (remove-duplicates (funcall #'db:history-prompt->values
prompt)
:test #'string=)))
(multiple-value-bind (matched-strings indices)
(uri-matcher actual-hint bag)
(when matched-strings
(values matched-strings
nil ;for fuzzy search common prefix does
;not makes sense; note also that
;setting this to nil will force
;selecting the first item in
;'complete-window' (see:
;complete-at-point and
;insert-selected-suggestion),
indices)))))))
indices))))))))
(defun complete-chat-message (hint)
(append (username-complete hint)

View File

@ -162,3 +162,5 @@ General Public License for more details."
(define-constant +octect-type+ '(unsigned-byte 8) :test #'equalp)
(define-constant +gemini-file-extension+ "gmi" :test #'string=)
(define-constant +file-scheme+ "file" :test #'string=)

View File

@ -487,12 +487,15 @@
(defun open-iri (iri main-window use-cache)
(handler-case
(let ((parsed-iri (iri:iri-parse iri)))
(if (iri:absolute-url-p iri)
(if (string= (uri:scheme parsed-iri)
gemini-constants:+gemini-scheme+)
(start-stream-iri iri main-window use-cache)
(client-os-utils:open-resource-with-external-program main-window iri))
(open-local-path iri main-window)))
(cond
((gemini-parser:gemini-iri-p iri)
(start-stream-iri iri main-window use-cache))
((or (null (uri:scheme parsed-iri))
(string= (uri:scheme parsed-iri)
constants:+file-scheme+))
(open-local-path (uri:path parsed-iri) main-window))
(t
(client-os-utils:open-resource-with-external-program main-window iri))))
(error (e)
(notify-request-error e))))

View File

@ -68,6 +68,7 @@
:+standard-editor+
:+octect-type+
:+gemini-file-extension+
:+file-scheme+
;; GUI
:+minimum-padding+
:+ps-file-dialog-filter+