@@ -19,67 +19,46 @@ import {
1919
2020 splitByLines , splitBySentences , splitByWords ,
2121} from './commands'
22+ import { improveCursorMovement_KeyDownListener , improveSearch_KeyDownListener } from './features'
2223import { getChosenBlocks , p , scrollToBlock } from './utils'
2324
2425
2526const DEV = process . env . NODE_ENV === 'development'
2627
2728const settingsSchema : SettingSchemaDesc [ ] = [
2829 {
29- key : 'splittingHeading' ,
30- title : '⛓️ Split & Join' ,
31- description : '' ,
32- type : 'heading' ,
33- default : null
30+ key : 'enableHomeEnd' ,
31+ title : 'Enable improved «Home» / «End» keys processing?' ,
32+ description : `
33+ Double-press the <code>Home</code> / <code>End</code> key (in edit mode) to go to the block start / end. <br/>
34+ MacOS's <code>⌘ ←</code> / <code>⌘ →</code> and Windows's <code>fn ←</code> / <code>fn →</code> are also supported. <br/>
35+ <p><img width="200px" src="https://github.com/stdword/logseq13-missing-commands/assets/1984175/4773523a-5900-4b48-b196-f6cb39799548"/></p>
36+ <i>Restriction</i>: This feature only works for natural lines of block, which have a «new line» character («\\n»). It does not work with lines created due to the size of the layout. In such cases, the only way to proceed is to press <code>Esc</code> to exit edit mode and then use the <code>←</code> or <code>→</code> arrow key to re-enter it. <br/>
37+ ` . trim ( ) ,
38+ type : 'enum' ,
39+ enumPicker : 'radio' ,
40+ enumChoices : [ 'Yes' , 'No' ] ,
41+ default : 'Yes' ,
3442 } ,
3543 {
36- key : 'storeChildBlocksIn ' ,
37- title : 'Where to store nested blocks when splitting the block ?' ,
44+ key : 'enableSearchImprovements ' ,
45+ title : 'Enable improved keys processing on Search ?' ,
3846 description : `
39- <span style="display: flex; gap: 1rem; align-items: center;">
40- <div>
41- <ul>
42- <li>First Last</li>
43- <ul>
44- <li>nested</li>
45- </ul>
46- </ul>
47- <p style="margin: 0px"> </p>
48- </div>
49- <div>→</div>
50- <div>
51- <ul>
52- <li>First</li>
53- <ul>
54- <li>nested</li>
55- </ul>
56- <li>Last</li>
57- </ul>
58- </div>
59- <div>OR</div>
60- <div>
61- <ul>
62- <li>First</li>
63- <li>Last</li>
64- <ul>
65- <li>nested</li>
66- </ul>
67- </ul>
68- </div>
69- </span>
47+ 1) Press <code>Tab</code> to fill the input with selected search item.<br/>
48+ <p><img width="600px" src="https://github.com/stdword/logseq13-missing-commands/assets/1984175/bf27f3a6-8464-4e1f-b967-e5e9efe46e21"/></p>
49+ ` . trim ( ) + '\n' + `
50+ 2) Press <code>←</code> arrow (with empty input) to fill the input with the current page name.<br/>
51+ <p><img width="600px" src="https://github.com/stdword/logseq13-missing-commands/assets/1984175/a083c0c1-604a-4514-8732-41b6a8c7b1ba"/></p>
7052 ` . trim ( ) ,
7153 type : 'enum' ,
7254 enumPicker : 'radio' ,
73- enumChoices : [ 'In the First block ' , 'In the Last block ' ] ,
74- default : 'In the Last block ' ,
55+ enumChoices : [ 'Yes ' , 'No ' ] ,
56+ default : 'Yes ' ,
7557 } ,
7658]
7759const settings_ : any = settingsSchema . reduce ( ( r , v ) => ( { ...r , [ v . key ] : v } ) , { } )
7860
7961
80- async function onAppSettingsChanged ( ) {
81- }
82-
8362async function init ( ) {
8463 if ( DEV ) {
8564 logseq . UI . showMsg (
@@ -89,29 +68,50 @@ async function init() {
8968 )
9069 }
9170
92- // logseq.useSettingsSchema(settingsSchema)
71+ logseq . useSettingsSchema ( settingsSchema )
9372
9473 console . info ( p `Loaded` )
9574}
75+ async function postInit ( settings ) {
76+ await onAppSettingsChanged ( settings , undefined )
77+ }
78+ async function onAppSettingsChanged ( current , old ) {
79+ if ( ! old || current . enableHomeEnd !== old . enableHomeEnd ) {
80+ parent . document . removeEventListener ( 'keydown' , improveCursorMovement_KeyDownListener )
81+ if ( current . enableHomeEnd === 'Yes' )
82+ parent . document . addEventListener ( 'keydown' , improveCursorMovement_KeyDownListener )
83+ }
84+
85+ if ( ! old || current . enableSearchImprovements !== old . enableSearchImprovements ) {
86+ parent . document . removeEventListener ( 'keydown' , improveSearch_KeyDownListener , true )
87+ if ( current . enableSearchImprovements === 'Yes' )
88+ parent . document . addEventListener ( 'keydown' , improveSearch_KeyDownListener , true )
89+ }
90+ }
9691
97- async function postInit ( ) {
98- await onAppSettingsChanged ( )
92+ const _emptyStyle = '/**/'
93+ function provideStyle ( key : string , style : string = _emptyStyle ) {
94+ logseq . provideStyle ( { key, style} )
95+ return ( ) => { logseq . provideStyle ( { key, style : _emptyStyle } ) }
9996}
10097
98+
10199async function main ( ) {
102100 await init ( )
103101
104102 const settings = logseq . settings !
103+ const settingsOff = logseq . onSettingsChanged ( onAppSettingsChanged )
105104
106- logseq . onSettingsChanged ( async ( old , new_ ) => {
107- await onAppSettingsChanged ( )
105+ logseq . beforeunload ( async ( ) => {
106+ settingsOff ( )
108107 } )
109108
109+
110110 function setting_storeChildBlocksIn ( ) {
111- return false
112- // return settings.storeChildBlocksIn === settings_.storeChildBlocksIn.enumChoices[0]
111+ return false // the last one
113112 }
114113
114+
115115 // Decoration
116116 logseq . App . registerCommandPalette ( {
117117 label : ICON + ' Toggle auto heading' , key : 'mc-1-auto-heading' ,
@@ -300,7 +300,7 @@ async function main() {
300300 } , ( e ) => shuffleBlocksCommand ( ) )
301301
302302
303- await postInit ( )
303+ await postInit ( settings )
304304}
305305
306306
0 commit comments