@@ -91,13 +91,7 @@ function AddEditInterface(settingsModel) {
9191 case "Enter" :
9292 e . preventDefault ( ) ;
9393 if ( e . target . classList . contains ( "directory" ) ) {
94- // replace search term with selected directory
95- inputEl . value = `${ addDirToLoginPath (
96- loginObj . login ,
97- e . target . getAttribute ( "value" )
98- ) } /`;
99- this . state . setLogin ( inputEl . value ) ;
100- inputEl . focus ( ) ;
94+ clickDirectoryHandler . apply ( this , [ e ] ) ;
10195 }
10296 break ;
10397 case "Home" :
@@ -142,10 +136,13 @@ function AddEditInterface(settingsModel) {
142136 */
143137 function clickDirectoryHandler ( e ) {
144138 e . preventDefault ( ) ;
145- var inputEl = document . querySelector ( "input.filePath" ) ;
146-
147- // replace search term with selected directory
148- inputEl . value = `${ addDirToLoginPath ( loginObj . login , e . target . getAttribute ( "value" ) ) } /` ;
139+ const inputEl = document . querySelector ( "input.filePath" ) ;
140+ const dir = e . target . getAttribute ( "value" ) ;
141+ const val = inputEl . value ;
142+ const pos = inputEl . selectionStart ;
143+ const newLeft = `${ addDirToLoginPath ( val . slice ( 0 , pos ) , dir ) } /` ;
144+ inputEl . value = newLeft + val . slice ( pos ) ;
145+ inputEl . selectionStart = inputEl . selectionEnd = newLeft . length ;
149146 this . state . setLogin ( inputEl . value ) ;
150147 inputEl . focus ( ) ;
151148 }
@@ -222,6 +219,19 @@ function AddEditInterface(settingsModel) {
222219 return `min-width: 65px; max-width: 442px; width: ${ length * 8 } px;` ;
223220 }
224221
222+ /**
223+ * Update login
224+ *
225+ * @since 3.11.0
226+ *
227+ * @param {object } vnode
228+ */
229+ function updateLogin ( vnode ) {
230+ const path = vnode . target . value ;
231+ const cursorPos = vnode . target . selectionStart ;
232+ this . setLogin ( path , path . slice ( 0 , cursorPos ) ) ;
233+ }
234+
225235 /**
226236 * Generate and set a new secret on the provided login object
227237 *
@@ -325,11 +335,12 @@ function AddEditInterface(settingsModel) {
325335 * @since 3.8.0
326336 *
327337 * @param {string } path
338+ * @param {string } pathPreceedingCursor
328339 */
329- setLogin : function ( path ) {
340+ setLogin : function ( path , pathPreceedingCursor ) {
330341 loginObj . login = path ;
331342 if ( canTree ) {
332- storeDirs = storeTree . search ( path ) ;
343+ storeDirs = storeTree . search ( pathPreceedingCursor ?? path ) ;
333344 } else {
334345 storeDirs = [ ] ;
335346 }
@@ -465,8 +476,10 @@ function AddEditInterface(settingsModel) {
465476 placeholder : "filename" ,
466477 value : loginObj . login ,
467478 style : `${ getPathWidth ( loginObj ) } ` ,
468- oninput : m . withAttr ( "value" , this . setLogin ) ,
469- onfocus : m . withAttr ( "value" , this . setLogin ) ,
479+ oninput : updateLogin . bind ( this ) ,
480+ onfocus : updateLogin . bind ( this ) ,
481+ onmouseup : updateLogin . bind ( this ) ,
482+ onkeyup : updateLogin . bind ( this ) ,
470483 onkeydown : pathKeyHandler . bind ( vnode ) ,
471484 } ) ,
472485 m ( `div.suffix${ editing ? ".disabled" : "" } ` , ".gpg" ) ,
0 commit comments