Skip to content

Commit

Permalink
resolve #376
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Feb 4, 2025
1 parent 6744d59 commit e84e0fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/modals/annotation-modals.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Setting, TFile, TextAreaComponent, MarkdownRenderer, RGB, ColorComponent, DropdownComponent } from 'obsidian';

import PDFPlus from 'main';
import { hexToRgb, hookInternalLinkMouseEventHandlers, rgbToHex } from 'utils';
import { getModifierNameInPlatform, hexToRgb, hookInternalLinkMouseEventHandlers, rgbToHex } from 'utils';
import { PDFDict } from '@cantoo/pdf-lib';
import { PDFPlusModal } from 'modals';

Expand Down Expand Up @@ -81,6 +81,10 @@ export class PDFAnnotationEditModal extends PDFAnnotationModal {

this.containerEl.addClass('pdf-plus-annotation-edit-modal');
this.buttonContainerEl = this.modalEl.createDiv();

this.scope.register(['Mod'], 'Enter', () => {
this.onSaveButtonClick();
});
}

async readOldValues() {
Expand Down Expand Up @@ -279,7 +283,21 @@ export class PDFAnnotationEditModal extends PDFAnnotationModal {
if (this.plugin.settings.renderMarkdownInStickyNote) {
setting.setDesc(`Press ${this.app.hotkeyManager.printHotkeyForCommand('markdown:toggle-preview')} to toggle preview.`);
} else {
setting.setDesc('Tip: There is an option called "Render markdown in annotation popups when the annotation has text contents".');
setting.setDesc(createFragment((el) => {
const anchorEl = createEl('a', {
text: '"Render markdown in annotation popups when the annotation has text contents"',
}, (el) => {
el.onclick = (evt) => {
const tab = this.plugin.openSettingTab();
tab.scrollTo('renderMarkdownInStickyNote', { behavior: 'smooth' });
tab.updateHeaderElClassOnScroll(evt);
}
});

el.append('Tip: There is an option called ');
el.append(anchorEl);
el.append('.');
}));
}
})
.addTextArea((textarea) => {
Expand Down Expand Up @@ -308,16 +326,24 @@ export class PDFAnnotationEditModal extends PDFAnnotationModal {
.setButtonText('Save')
.setCta()
.onClick(() => {
this.writeNewValues();
this.close();
this.onSaveButtonClick();
});
})
.addButton((button) => {
button
.setButtonText('Cancel')
.onClick(() => this.close());
})
.then((setting) => setting.setClass('no-border'));
.setClass('no-border');
this.buttonContainerEl.createDiv({
cls: 'pdf-plus-annotation-edit-modal-save-instructions',
text: `Press ${getModifierNameInPlatform('Mod')} + Enter to save.`
});
}

onSaveButtonClick() {
this.writeNewValues();
this.close();
}

async onOpen() {
Expand Down
6 changes: 6 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@ body.pdf-plus-backlink-selection-underline {
padding-top: var(--size-4-2);
}
}

.pdf-plus-annotation-edit-modal-save-instructions {
color: var(--text-muted);
font-size: calc(var(--font-text-size) * 0.65);
text-align: end;
}
}

.popupWrapper {
Expand Down

0 comments on commit e84e0fb

Please sign in to comment.