From 4ee09ae3015acdff803c82cf069042a359b163b9 Mon Sep 17 00:00:00 2001 From: cage Date: Fri, 7 Apr 2023 13:05:36 +0200 Subject: [PATCH] - allowed complete local path even when using file scheme ('file://'). --- src/complete.lisp | 34 +++++++++++++++++++++------------ src/constants.lisp | 2 ++ src/gui/client/main-window.lisp | 15 +++++++++------ src/package.lisp | 1 + 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/complete.lisp b/src/complete.lisp index 9f44a1a..3a53bb4 100644 --- a/src/complete.lisp +++ b/src/complete.lisp @@ -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) diff --git a/src/constants.lisp b/src/constants.lisp index 4ff0172..1cc86b0 100644 --- a/src/constants.lisp +++ b/src/constants.lisp @@ -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=) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index 337a72c..c930253 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -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)))) diff --git a/src/package.lisp b/src/package.lisp index efdee6a..ad872f3 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -68,6 +68,7 @@ :+standard-editor+ :+octect-type+ :+gemini-file-extension+ + :+file-scheme+ ;; GUI :+minimum-padding+ :+ps-file-dialog-filter+