@@ -4,6 +4,7 @@ import { SessionPasswordService } from 'src/services/SessionPasswordService';
4
4
import { UiHelper } from 'src/services/UiHelper' ;
5
5
import { CryptoHelper } from '../../services/CryptoHelper' ;
6
6
import { IFeatureWholeNoteEncryptSettings } from './IFeatureWholeNoteEncryptSettings' ;
7
+ import { ObsidianEx } from 'src/services/ObsidianEx' ;
7
8
8
9
enum EncryptedFileContentViewStateEnum {
9
10
init ,
@@ -28,6 +29,7 @@ export class EncryptedFileContentView extends TextFileView {
28
29
private iconChangePassword = 'key' ;
29
30
30
31
// State
32
+ settings : IFeatureWholeNoteEncryptSettings ;
31
33
currentView : EncryptedFileContentViewStateEnum = EncryptedFileContentViewStateEnum . init ;
32
34
encryptionPassword = '' ;
33
35
hint = '' ;
@@ -44,6 +46,7 @@ export class EncryptedFileContentView extends TextFileView {
44
46
constructor ( leaf : WorkspaceLeaf , settings :IFeatureWholeNoteEncryptSettings ) {
45
47
super ( leaf ) ;
46
48
49
+ this . settings = settings ;
47
50
this . defaultEditNoteView = ( settings . defaultView as EditViewEnum ) ?? EditViewEnum . source ;
48
51
this . currentEditNoteMode = this . defaultEditNoteView ;
49
52
@@ -56,10 +59,9 @@ export class EncryptedFileContentView extends TextFileView {
56
59
this . elActionReadingView . hide ( ) ;
57
60
this . elActionIconLockNote . hide ( ) ;
58
61
this . elActionChangePassword . hide ( ) ;
59
-
60
- this . contentEl . style . display = 'flex' ;
61
- this . contentEl . style . flexDirection = 'column' ;
62
- this . contentEl . style . alignItems = 'center' ;
62
+
63
+ this . containerEl . classList . add ( 'meld-encrypt-encrypted-note-view' ) ;
64
+ this . contentEl . classList . add ( 'meld-encrypt-encrypted-note-view-content' ) ;
63
65
64
66
}
65
67
@@ -121,13 +123,18 @@ export class EncryptedFileContentView extends TextFileView {
121
123
super . onPaneMenu ( menu , source ) ;
122
124
}
123
125
124
- private addTitle ( title :string ) : HTMLElement {
125
- return this . contentEl . createDiv ( {
126
+ private addHeader ( container : HTMLElement , title :string ) {
127
+ container . createDiv ( {
126
128
text : `🔐 ${ title } 🔐` ,
127
- attr : {
128
- style : 'margin-bottom:2em;'
129
- }
129
+ cls : 'encrypted-note-message'
130
130
} ) ;
131
+
132
+ if ( ObsidianEx . showInlineTitle ) {
133
+ container . createDiv ( {
134
+ text : this . file ?. basename ,
135
+ cls : 'inline-title'
136
+ } ) ;
137
+ }
131
138
}
132
139
133
140
private validatePassword ( pw : string ) : string {
@@ -142,14 +149,14 @@ export class EncryptedFileContentView extends TextFileView {
142
149
return passwordMatch ? '' :'Password doesn\'t match' ;
143
150
}
144
151
145
- private addNewNoteView ( ) {
152
+ private addNewNoteView ( container : HTMLElement ) {
146
153
147
- this . addTitle ( 'This note will be encrypted' ) ;
154
+ this . addHeader ( container , 'This note will be encrypted' ) ;
148
155
149
156
//console.debug('createDecryptNoteView', { "hint": this.hint} );
150
- const container = this . addInputContainer ( ) ;
157
+ const inputContainer = this . addUserInputContainer ( container ) ;
151
158
152
- new Setting ( container )
159
+ new Setting ( inputContainer )
153
160
. setDesc ( 'Please provide a password and hint to start editing this note.' )
154
161
;
155
162
@@ -164,15 +171,18 @@ export class EncryptedFileContentView extends TextFileView {
164
171
//set password and hint and open note
165
172
this . encryptionPassword = password ;
166
173
this . hint = hint ;
174
+
167
175
// initial content of new note
168
- this . currentEditorSourceText = `# ${ this . file . basename } ` ;
176
+ if ( ! ObsidianEx . showInlineTitle ) {
177
+ this . currentEditorSourceText = `# ${ this . file . basename } \n\n\n` ;
178
+ }
169
179
170
180
await this . encodeAndSave ( ) ;
171
181
172
182
SessionPasswordService . putByPath ( { password : password , hint : hint } , this . file . path ) ;
173
183
174
184
this . currentEditNoteMode = EditViewEnum . source ;
175
- this . refreshView ( EncryptedFileContentViewStateEnum . editNote ) ;
185
+ this . refreshView ( EncryptedFileContentViewStateEnum . editNote ) ;
176
186
177
187
}
178
188
}
@@ -183,7 +193,7 @@ export class EncryptedFileContentView extends TextFileView {
183
193
let hint = bestGuessPassAndHint . hint ;
184
194
185
195
const sPassword = UiHelper . buildPasswordSetting ( {
186
- container,
196
+ container : inputContainer ,
187
197
name :'Password:' ,
188
198
autoFocus : true ,
189
199
initialValue : password ,
@@ -201,7 +211,7 @@ export class EncryptedFileContentView extends TextFileView {
201
211
} ) ;
202
212
203
213
const sConfirm = UiHelper . buildPasswordSetting ( {
204
- container,
214
+ container : inputContainer ,
205
215
name :'Confirm:' ,
206
216
autoFocus : false ,
207
217
onChangeCallback : ( value ) => {
@@ -218,7 +228,7 @@ export class EncryptedFileContentView extends TextFileView {
218
228
}
219
229
} ) ;
220
230
221
- const sHint = new Setting ( container )
231
+ const sHint = new Setting ( inputContainer )
222
232
. setName ( "Hint:" )
223
233
. addText ( ( tc ) => {
224
234
tc . setValue ( hint ) ;
@@ -234,7 +244,7 @@ export class EncryptedFileContentView extends TextFileView {
234
244
}
235
245
} ) ;
236
246
237
- new Setting ( container )
247
+ new Setting ( inputContainer )
238
248
. addButton ( bc => {
239
249
bc
240
250
. setCta ( )
@@ -247,18 +257,18 @@ export class EncryptedFileContentView extends TextFileView {
247
257
248
258
}
249
259
250
- private addDecryptNoteView ( ) {
260
+ private addDecryptNoteView ( container : HTMLElement ) {
251
261
252
- this . addTitle ( 'This note is encrypted' ) ;
262
+ this . addHeader ( container , 'This note is encrypted' ) ;
253
263
254
- const container = this . addInputContainer ( ) ;
264
+ const inputContainer = this . addUserInputContainer ( container ) ;
255
265
256
- new Setting ( container )
266
+ new Setting ( inputContainer )
257
267
. setDesc ( 'Please provide a password to unlock this note.' )
258
268
;
259
269
260
270
UiHelper . buildPasswordSetting ( {
261
- container,
271
+ container : inputContainer ,
262
272
name :'Password:' ,
263
273
autoFocus : true ,
264
274
placeholder : this . formatHint ( this . hint ) ,
@@ -268,7 +278,7 @@ export class EncryptedFileContentView extends TextFileView {
268
278
onEnterCallback : async ( ) => await this . handleDecryptButtonClick ( )
269
279
} ) ;
270
280
271
- new Setting ( container )
281
+ new Setting ( inputContainer )
272
282
. addButton ( bc => {
273
283
bc
274
284
. setCta ( )
@@ -316,68 +326,66 @@ export class EncryptedFileContentView extends TextFileView {
316
326
}
317
327
}
318
328
319
- private addEditorSourceView ( ) {
329
+ private addEditorSourceView ( container : HTMLElement ) {
320
330
321
331
this . elActionReadingView . show ( ) ;
322
332
this . elActionIconLockNote . show ( ) ;
323
333
this . elActionChangePassword . show ( ) ;
324
334
325
- this . addTitle ( 'Editing an encrypted note' ) ;
335
+ this . addHeader ( container , 'Editing an encrypted note' ) ;
326
336
327
337
// build source view
328
- const container = this . contentEl . createDiv ( ) ;
329
- container . contentEditable = 'true' ;
330
- container . style . flexGrow = '1' ;
331
- container . style . alignSelf = 'stretch' ;
332
-
333
- container . innerText = this . currentEditorSourceText ;
338
+ const editorContainer = container . createDiv ( { cls :'editor-source-view' } ) ;
339
+ editorContainer . spellcheck = true ;
340
+ editorContainer . autocapitalize = 'on' ;
341
+ editorContainer . translate = false ;
342
+ editorContainer . contentEditable = 'true' ;
343
+ //editorContainer.autocorrect="on"
344
+ editorContainer . innerText = this . currentEditorSourceText ;
334
345
335
- container . focus ( ) ;
336
346
337
- container . on ( 'input' , '*' , async ( ev , target ) => {
338
- console . debug ( { container} ) ;
339
- this . currentEditorSourceText = container . innerText ;
347
+ editorContainer . focus ( ) ;
348
+
349
+ editorContainer . on ( 'input' , '*' , async ( ev , target ) => {
350
+ console . debug ( { container : editorContainer } ) ;
351
+ this . currentEditorSourceText = editorContainer . innerText ;
340
352
await this . encodeAndSave ( ) ;
341
353
} ) ;
342
354
343
355
}
344
356
345
- private addEditorReadingView ( ) {
357
+ private addEditorReadingView ( container : HTMLElement ) {
346
358
347
359
this . elActionEditView . show ( ) ;
348
360
this . elActionIconLockNote . show ( ) ;
349
361
this . elActionChangePassword . show ( ) ;
350
362
351
- this . addTitle ( 'Reading an encrypted note' ) ;
363
+ this . addHeader ( container , 'Reading an encrypted note' ) ;
364
+
365
+ const readingContainer = container . createDiv ( { cls :'editor-reading-view' } ) ;
352
366
353
- const container = this . contentEl . createDiv ( ) ;
354
- container . contentEditable = 'false' ;
355
- container . style . flexGrow = '1' ;
356
- container . style . alignSelf = 'stretch' ;
357
367
358
368
// build reading view
359
369
MarkdownRenderer . renderMarkdown (
360
370
this . currentEditorSourceText ,
361
- container ,
371
+ readingContainer ,
362
372
this . file . path ,
363
373
this
364
- ) ;
374
+ ) . catch ( reason => {
375
+ console . error ( reason ) ;
376
+ } ) ;
365
377
366
378
}
367
379
368
- private addInputContainer ( ) : HTMLElement {
369
- return this . contentEl . createDiv ( {
370
- 'attr' : {
371
- 'style' : 'width:100%; max-width:400px;'
372
- }
373
- } ) ;
380
+ private addUserInputContainer ( container : HTMLElement ) : HTMLElement {
381
+ return container . createDiv ( { cls : 'input-container' } ) ;
374
382
}
375
383
376
- private addChangePasswordView ( ) {
384
+ private addChangePasswordView ( container : HTMLElement ) {
377
385
378
- this . addTitle ( 'Change encrypted note password' ) ;
386
+ this . addHeader ( container , 'Change encrypted note password' ) ;
379
387
380
- const container = this . addInputContainer ( ) ;
388
+ const inputContainer = this . addUserInputContainer ( container ) ;
381
389
382
390
let newPassword = '' ;
383
391
let confirm = '' ;
@@ -405,7 +413,7 @@ export class EncryptedFileContentView extends TextFileView {
405
413
}
406
414
407
415
const sNewPassword = UiHelper . buildPasswordSetting ( {
408
- container,
416
+ container : inputContainer ,
409
417
name : 'New Password:' ,
410
418
autoFocus : true ,
411
419
onChangeCallback : ( value ) => {
@@ -422,7 +430,7 @@ export class EncryptedFileContentView extends TextFileView {
422
430
} ) ;
423
431
424
432
const sConfirm = UiHelper . buildPasswordSetting ( {
425
- container,
433
+ container : inputContainer ,
426
434
name : 'Confirm:' ,
427
435
onChangeCallback : ( value ) => {
428
436
confirm = value ;
@@ -439,7 +447,7 @@ export class EncryptedFileContentView extends TextFileView {
439
447
}
440
448
} ) ;
441
449
442
- const sHint = new Setting ( container )
450
+ const sHint = new Setting ( inputContainer )
443
451
. setName ( "New Hint:" )
444
452
. addText ( ( tc ) => {
445
453
tc . onChange ( v => {
@@ -454,7 +462,7 @@ export class EncryptedFileContentView extends TextFileView {
454
462
}
455
463
} ) ;
456
464
457
- new Setting ( container )
465
+ new Setting ( inputContainer )
458
466
. addButton ( bc => {
459
467
bc
460
468
. removeCta ( )
@@ -491,7 +499,10 @@ export class EncryptedFileContentView extends TextFileView {
491
499
private refreshView (
492
500
newView : EncryptedFileContentViewStateEnum
493
501
) {
494
-
502
+
503
+ this . currentView = newView ;
504
+
505
+
495
506
//console.debug('refreshView',{'currentView':this.currentView, newView});
496
507
this . elActionEditView . hide ( ) ;
497
508
this . elActionReadingView . hide ( ) ;
@@ -500,29 +511,34 @@ export class EncryptedFileContentView extends TextFileView {
500
511
501
512
// clear view
502
513
this . contentEl . empty ( ) ;
503
-
504
- this . currentView = newView ;
514
+ if ( ObsidianEx . readableLineLength ) {
515
+ this . contentEl . classList . add ( 'is-readable-line-width' ) ;
516
+ } else {
517
+ this . contentEl . classList . remove ( 'is-readable-line-width' ) ;
518
+ }
519
+
520
+ const contentContainer = this . contentEl . createDiv ( { cls : 'content-container' } ) ;
505
521
506
522
switch ( this . currentView ) {
507
523
case EncryptedFileContentViewStateEnum . newNote :
508
- this . addNewNoteView ( ) ;
524
+ this . addNewNoteView ( contentContainer ) ;
509
525
break ;
510
526
511
527
case EncryptedFileContentViewStateEnum . decryptNote :
512
- this . addDecryptNoteView ( ) ;
528
+ this . addDecryptNoteView ( contentContainer ) ;
513
529
break ;
514
530
515
531
case EncryptedFileContentViewStateEnum . editNote :
516
532
if ( this . currentEditNoteMode == EditViewEnum . source ) {
517
- this . addEditorSourceView ( ) ;
533
+ this . addEditorSourceView ( contentContainer ) ;
518
534
} else {
519
535
// default to reading
520
- this . addEditorReadingView ( ) ;
536
+ this . addEditorReadingView ( contentContainer ) ;
521
537
}
522
538
break ;
523
539
524
540
case EncryptedFileContentViewStateEnum . changePassword :
525
- this . addChangePasswordView ( ) ;
541
+ this . addChangePasswordView ( contentContainer ) ;
526
542
break ;
527
543
}
528
544
0 commit comments