Browse Source

Allow editing and saving decrypted text when decrypting inline text

pull/166/head
naturecodevoid 1 year ago
parent
commit
3dec29d643
  1. 1
      .gitignore
  2. 14
      src/features/feature-inplace-encrypt/DecryptModal.ts
  3. 1
      src/features/feature-inplace-encrypt/Decryptable.ts
  4. 13
      src/features/feature-inplace-encrypt/FeatureInplaceEncrypt.ts
  5. 2
      src/features/feature-inplace-encrypt/featureInplaceTextAnalysis.ts

1
.gitignore vendored

@ -9,4 +9,5 @@ node_modules @@ -9,4 +9,5 @@ node_modules
dist
*.map
Obsidian Encrypt - test-vault
test-vault

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

@ -3,6 +3,7 @@ import { App, Modal, Notice, Setting, TextAreaComponent } from 'obsidian'; @@ -3,6 +3,7 @@ import { App, Modal, Notice, Setting, TextAreaComponent } from 'obsidian';
export default class DecryptModal extends Modal {
text: string;
decryptInPlace = false;
save = false;
canDecryptInPlace = true;
@ -28,7 +29,6 @@ export default class DecryptModal extends Modal { @@ -28,7 +29,6 @@ export default class DecryptModal extends Modal {
cTextArea = cb;
cb.setValue(this.text);
cb.inputEl.setSelectionRange(0,0)
cb.inputEl.readOnly = true;
cb.inputEl.rows = 10;
})
;
@ -36,6 +36,17 @@ export default class DecryptModal extends Modal { @@ -36,6 +36,17 @@ export default class DecryptModal extends Modal {
const sActions = new Setting(contentEl);
sActions
.addButton(cb => {
cb
.setButtonText('Save')
.onClick( evt =>{
this.save = true;
this.text = cTextArea.getValue();
this.close();
});
});
sActions
.addButton( cb =>{
cb
@ -53,6 +64,7 @@ export default class DecryptModal extends Modal { @@ -53,6 +64,7 @@ export default class DecryptModal extends Modal {
.setButtonText('Decrypt in-place')
.onClick( evt =>{
this.decryptInPlace = true;
this.text = cTextArea.getValue();
this.close();
});
});

1
src/features/feature-inplace-encrypt/Decryptable.ts

@ -2,4 +2,5 @@ export class Decryptable{ @@ -2,4 +2,5 @@ export class Decryptable{
version: number;
base64CipherText:string;
hint:string;
showInReadingView: boolean;
}

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

@ -609,11 +609,20 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{ @@ -609,11 +609,20 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{
editor.replaceSelection(decryptedText);
} else {
const decryptModal = new DecryptModal(this.plugin.app, '🔓', decryptedText );
decryptModal.onClose = () => {
decryptModal.onClose = async () => {
editor.focus();
if (decryptModal.decryptInPlace) {
editor.setSelection(selectionStart, selectionEnd);
editor.replaceSelection(decryptedText);
editor.replaceSelection(decryptModal.text);
} else if (decryptModal.save) {
const crypto = CryptoHelperFactory.BuildDefault();
const encodedText = this.encodeEncryption(
await crypto.encryptToBase64(decryptModal.text, password),
decryptable.hint ?? "",
decryptable.showInReadingView
);
editor.setSelection(selectionStart, selectionEnd);
editor.replaceSelection(encodedText);
}
}
decryptModal.open();

2
src/features/feature-inplace-encrypt/featureInplaceTextAnalysis.ts

@ -91,7 +91,7 @@ export class FeatureInplaceTextAnalysis{ @@ -91,7 +91,7 @@ export class FeatureInplaceTextAnalysis{
}else{
result.base64CipherText = content;
}
result.showInReadingView = !this.prefix.includes("%%");
return result;
}

Loading…
Cancel
Save