Skip to content

Commit 0331af7

Browse files
authored
Merge pull request meld-cp#90 from meld-cp:meld-cp/issue88
Meld-cp/issue88
2 parents 6000cf1 + 216aa8f commit 0331af7

File tree

7 files changed

+158
-72
lines changed

7 files changed

+158
-72
lines changed

src/features/feature-inplace-encrypt/DecryptModal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export default class DecryptModal extends Modal {
1919
onOpen() {
2020
const { contentEl } = this;
2121

22+
contentEl.empty();
23+
contentEl.classList.add('meld-encrypt-decrypt-modal');
24+
2225
let cTextArea : TextAreaComponent;
2326
const sText = new Setting(contentEl)
2427
.addTextArea( cb=>{
@@ -27,9 +30,6 @@ export default class DecryptModal extends Modal {
2730
cb.inputEl.setSelectionRange(0,0)
2831
cb.inputEl.readOnly = true;
2932
cb.inputEl.rows = 10;
30-
cb.inputEl.style.width = '100%';
31-
cb.inputEl.style.minHeight = '3em';
32-
cb.inputEl.style.resize = 'vertical';
3333
})
3434
;
3535
sText.settingEl.querySelector('.setting-item-info')?.remove();

src/features/feature-inplace-encrypt/FeatureInplaceEncrypt.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{
103103
const elPreIndicator = createSpan( { text: textBeforeIndicator } );
104104
const elPostIndicator = createSpan( { text: textAfterIndicator } );
105105

106-
const elIndicator = createSpan( { text: '🔐' } );
107-
elIndicator.style.cursor = 'pointer';
106+
const elIndicator = createSpan( { text: '🔐', cls: 'meld-encrypt-inline-reading-marker' } );
108107
elIndicator.onClickEvent( async () =>
109108
await this.handleReadingIndicatorClick(
110109
ctx.sourcePath,

src/features/feature-inplace-encrypt/PasswordModal.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default class PasswordModal extends Modal {
3737

3838
contentEl.empty();
3939

40-
//this.contentEl.style.width = 'auto';
4140
this.invalidate();
4241

4342
let password = this.defaultPassword ?? '';

src/features/feature-whole-note-encrypt/EncryptedFileContentView.ts

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SessionPasswordService } from 'src/services/SessionPasswordService';
44
import { UiHelper } from 'src/services/UiHelper';
55
import { CryptoHelper } from '../../services/CryptoHelper';
66
import { IFeatureWholeNoteEncryptSettings } from './IFeatureWholeNoteEncryptSettings';
7+
import { ObsidianEx } from 'src/services/ObsidianEx';
78

89
enum EncryptedFileContentViewStateEnum{
910
init,
@@ -28,6 +29,7 @@ export class EncryptedFileContentView extends TextFileView {
2829
private iconChangePassword = 'key';
2930

3031
// State
32+
settings : IFeatureWholeNoteEncryptSettings;
3133
currentView : EncryptedFileContentViewStateEnum = EncryptedFileContentViewStateEnum.init;
3234
encryptionPassword = '';
3335
hint = '';
@@ -44,6 +46,7 @@ export class EncryptedFileContentView extends TextFileView {
4446
constructor( leaf: WorkspaceLeaf, settings:IFeatureWholeNoteEncryptSettings ) {
4547
super(leaf);
4648

49+
this.settings = settings;
4750
this.defaultEditNoteView = ( settings.defaultView as EditViewEnum ) ?? EditViewEnum.source;
4851
this.currentEditNoteMode = this.defaultEditNoteView;
4952

@@ -56,10 +59,9 @@ export class EncryptedFileContentView extends TextFileView {
5659
this.elActionReadingView.hide();
5760
this.elActionIconLockNote.hide();
5861
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');
6365

6466
}
6567

@@ -121,13 +123,18 @@ export class EncryptedFileContentView extends TextFileView {
121123
super.onPaneMenu(menu,source);
122124
}
123125

124-
private addTitle( title:string ) : HTMLElement{
125-
return this.contentEl.createDiv({
126+
private addHeader( container:HTMLElement, title:string ){
127+
container.createDiv({
126128
text : `🔐 ${title} 🔐`,
127-
attr : {
128-
style: 'margin-bottom:2em;'
129-
}
129+
cls : 'encrypted-note-message'
130130
});
131+
132+
if (ObsidianEx.showInlineTitle){
133+
container.createDiv({
134+
text: this.file?.basename,
135+
cls: 'inline-title'
136+
} );
137+
}
131138
}
132139

133140
private validatePassword ( pw: string ) : string {
@@ -142,14 +149,14 @@ export class EncryptedFileContentView extends TextFileView {
142149
return passwordMatch ? '' :'Password doesn\'t match';
143150
}
144151

145-
private addNewNoteView() {
152+
private addNewNoteView( container: HTMLElement ) {
146153

147-
this.addTitle('This note will be encrypted');
154+
this.addHeader(container, 'This note will be encrypted');
148155

149156
//console.debug('createDecryptNoteView', { "hint": this.hint} );
150-
const container = this.addInputContainer();
157+
const inputContainer = this.addUserInputContainer( container );
151158

152-
new Setting(container)
159+
new Setting(inputContainer)
153160
.setDesc('Please provide a password and hint to start editing this note.')
154161
;
155162

@@ -164,15 +171,18 @@ export class EncryptedFileContentView extends TextFileView {
164171
//set password and hint and open note
165172
this.encryptionPassword = password;
166173
this.hint = hint;
174+
167175
// 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+
}
169179

170180
await this.encodeAndSave();
171181

172182
SessionPasswordService.putByPath( { password: password, hint: hint }, this.file.path );
173183

174184
this.currentEditNoteMode = EditViewEnum.source;
175-
this.refreshView(EncryptedFileContentViewStateEnum.editNote);
185+
this.refreshView( EncryptedFileContentViewStateEnum.editNote );
176186

177187
}
178188
}
@@ -183,7 +193,7 @@ export class EncryptedFileContentView extends TextFileView {
183193
let hint = bestGuessPassAndHint.hint;
184194

185195
const sPassword = UiHelper.buildPasswordSetting({
186-
container,
196+
container: inputContainer,
187197
name:'Password:',
188198
autoFocus : true,
189199
initialValue: password,
@@ -201,7 +211,7 @@ export class EncryptedFileContentView extends TextFileView {
201211
});
202212

203213
const sConfirm = UiHelper.buildPasswordSetting({
204-
container,
214+
container: inputContainer,
205215
name:'Confirm:',
206216
autoFocus : false,
207217
onChangeCallback: (value) => {
@@ -218,7 +228,7 @@ export class EncryptedFileContentView extends TextFileView {
218228
}
219229
});
220230

221-
const sHint = new Setting(container)
231+
const sHint = new Setting(inputContainer)
222232
.setName("Hint:")
223233
.addText((tc) =>{
224234
tc.setValue(hint);
@@ -234,7 +244,7 @@ export class EncryptedFileContentView extends TextFileView {
234244
}
235245
});
236246

237-
new Setting(container)
247+
new Setting(inputContainer)
238248
.addButton( bc => {
239249
bc
240250
.setCta()
@@ -247,18 +257,18 @@ export class EncryptedFileContentView extends TextFileView {
247257

248258
}
249259

250-
private addDecryptNoteView() {
260+
private addDecryptNoteView( container: HTMLElement ) {
251261

252-
this.addTitle('This note is encrypted');
262+
this.addHeader( container, 'This note is encrypted');
253263

254-
const container = this.addInputContainer();
264+
const inputContainer = this.addUserInputContainer( container );
255265

256-
new Setting(container)
266+
new Setting(inputContainer)
257267
.setDesc('Please provide a password to unlock this note.')
258268
;
259269

260270
UiHelper.buildPasswordSetting({
261-
container,
271+
container: inputContainer,
262272
name:'Password:',
263273
autoFocus : true,
264274
placeholder: this.formatHint(this.hint),
@@ -268,7 +278,7 @@ export class EncryptedFileContentView extends TextFileView {
268278
onEnterCallback: async () => await this.handleDecryptButtonClick()
269279
});
270280

271-
new Setting(container)
281+
new Setting(inputContainer)
272282
.addButton( bc => {
273283
bc
274284
.setCta()
@@ -316,68 +326,66 @@ export class EncryptedFileContentView extends TextFileView {
316326
}
317327
}
318328

319-
private addEditorSourceView() {
329+
private addEditorSourceView( container: HTMLElement ) {
320330

321331
this.elActionReadingView.show();
322332
this.elActionIconLockNote.show();
323333
this.elActionChangePassword.show();
324334

325-
this.addTitle('Editing an encrypted note');
335+
this.addHeader( container, 'Editing an encrypted note');
326336

327337
// 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;
334345

335-
container.focus();
336346

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;
340352
await this.encodeAndSave();
341353
});
342354

343355
}
344356

345-
private addEditorReadingView() {
357+
private addEditorReadingView( container: HTMLElement ) {
346358

347359
this.elActionEditView.show();
348360
this.elActionIconLockNote.show();
349361
this.elActionChangePassword.show();
350362

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'});
352366

353-
const container = this.contentEl.createDiv();
354-
container.contentEditable = 'false';
355-
container.style.flexGrow = '1';
356-
container.style.alignSelf = 'stretch';
357367

358368
// build reading view
359369
MarkdownRenderer.renderMarkdown(
360370
this.currentEditorSourceText,
361-
container,
371+
readingContainer,
362372
this.file.path,
363373
this
364-
);
374+
).catch( reason => {
375+
console.error( reason );
376+
});
365377

366378
}
367379

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' });
374382
}
375383

376-
private addChangePasswordView() {
384+
private addChangePasswordView( container: HTMLElement ) {
377385

378-
this.addTitle('Change encrypted note password');
386+
this.addHeader( container, 'Change encrypted note password' );
379387

380-
const container = this.addInputContainer();
388+
const inputContainer = this.addUserInputContainer( container );
381389

382390
let newPassword = '';
383391
let confirm = '';
@@ -405,7 +413,7 @@ export class EncryptedFileContentView extends TextFileView {
405413
}
406414

407415
const sNewPassword = UiHelper.buildPasswordSetting({
408-
container,
416+
container: inputContainer,
409417
name: 'New Password:',
410418
autoFocus: true,
411419
onChangeCallback: (value) =>{
@@ -422,7 +430,7 @@ export class EncryptedFileContentView extends TextFileView {
422430
});
423431

424432
const sConfirm = UiHelper.buildPasswordSetting({
425-
container,
433+
container: inputContainer,
426434
name: 'Confirm:',
427435
onChangeCallback: (value) =>{
428436
confirm = value;
@@ -439,7 +447,7 @@ export class EncryptedFileContentView extends TextFileView {
439447
}
440448
});
441449

442-
const sHint = new Setting(container)
450+
const sHint = new Setting(inputContainer)
443451
.setName("New Hint:")
444452
.addText((tc) =>{
445453
tc.onChange( v => {
@@ -454,7 +462,7 @@ export class EncryptedFileContentView extends TextFileView {
454462
}
455463
});
456464

457-
new Setting(container)
465+
new Setting(inputContainer)
458466
.addButton( bc => {
459467
bc
460468
.removeCta()
@@ -491,7 +499,10 @@ export class EncryptedFileContentView extends TextFileView {
491499
private refreshView(
492500
newView: EncryptedFileContentViewStateEnum
493501
){
494-
502+
503+
this.currentView = newView;
504+
505+
495506
//console.debug('refreshView',{'currentView':this.currentView, newView});
496507
this.elActionEditView.hide();
497508
this.elActionReadingView.hide();
@@ -500,29 +511,34 @@ export class EncryptedFileContentView extends TextFileView {
500511

501512
// clear view
502513
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'});
505521

506522
switch (this.currentView) {
507523
case EncryptedFileContentViewStateEnum.newNote:
508-
this.addNewNoteView();
524+
this.addNewNoteView( contentContainer );
509525
break;
510526

511527
case EncryptedFileContentViewStateEnum.decryptNote:
512-
this.addDecryptNoteView();
528+
this.addDecryptNoteView( contentContainer );
513529
break;
514530

515531
case EncryptedFileContentViewStateEnum.editNote:
516532
if ( this.currentEditNoteMode == EditViewEnum.source ){
517-
this.addEditorSourceView();
533+
this.addEditorSourceView( contentContainer );
518534
} else{
519535
// default to reading
520-
this.addEditorReadingView();
536+
this.addEditorReadingView( contentContainer );
521537
}
522538
break;
523539

524540
case EncryptedFileContentViewStateEnum.changePassword:
525-
this.addChangePasswordView();
541+
this.addChangePasswordView( contentContainer );
526542
break;
527543
}
528544

0 commit comments

Comments
 (0)