diff --git a/app/assets/javascripts/components/SearchOptions.tsx b/app/assets/javascripts/components/SearchOptions.tsx index 9db46eeda..2099169a4 100644 --- a/app/assets/javascripts/components/SearchOptions.tsx +++ b/app/assets/javascripts/components/SearchOptions.tsx @@ -27,7 +27,10 @@ const SearchOptions = observer(({ appState }: Props) => { } = searchOptions; const [open, setOpen] = useState(false); - const [optionsPanelTop, setOptionsPanelTop] = useState(0); + const [position, setPosition] = useState({ + top: 0, + right: 0, + }); const buttonRef = useRef(); const panelRef = useRef(); const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef, setOpen); @@ -45,9 +48,12 @@ const SearchOptions = observer(({ appState }: Props) => { { - const { height } = buttonRef.current.getBoundingClientRect(); - setOptionsPanelTop(height); - setOpen((prevOpen) => !prevOpen); + const rect = buttonRef.current.getBoundingClientRect(); + setPosition({ + top: rect.bottom, + right: document.body.clientWidth - rect.right, + }); + setOpen(!open); }} > { { } } - async openSessionRevision(revision: HistoryEntry) { + async openSessionRevision(revision: HistoryEntry & { previewTitle: () => string }) { this.application.presentRevisionPreviewModal( revision.payload.uuid, - revision.payload.content + revision.payload.content, + revision.previewTitle() ); } @@ -84,7 +85,8 @@ class HistoryMenuCtrl extends PureViewCtrl { } this.application.presentRevisionPreviewModal( remoteRevision.payload.uuid, - remoteRevision.payload.content + remoteRevision.payload.content, + this.previewRemoteHistoryTitle(revision) ); } @@ -154,7 +156,7 @@ class HistoryMenuCtrl extends PureViewCtrl { this.reloadState(); } - previewRemoteHistoryTitle(revision: SingleRevision) { + previewRemoteHistoryTitle(revision: RevisionListEntry) { return new Date(revision.created_at).toLocaleString(); } } diff --git a/app/assets/javascripts/directives/views/revisionPreviewModal.ts b/app/assets/javascripts/directives/views/revisionPreviewModal.ts index a67755eb1..3332fbada 100644 --- a/app/assets/javascripts/directives/views/revisionPreviewModal.ts +++ b/app/assets/javascripts/directives/views/revisionPreviewModal.ts @@ -24,6 +24,7 @@ class RevisionPreviewModalCtrl extends PureViewCtrl implements RevisionPreviewSc $timeout: ng.ITimeoutService uuid!: string content!: PayloadContent + title?: string application!: WebApplication unregisterComponent?: any note!: SNNote @@ -139,6 +140,7 @@ export class RevisionPreviewModal extends WebDirective { this.scope = { uuid: '=', content: '=', + title: '=', application: '=' }; } diff --git a/app/assets/javascripts/ui_models/application.ts b/app/assets/javascripts/ui_models/application.ts index 3577b4703..80080ccd2 100644 --- a/app/assets/javascripts/ui_models/application.ts +++ b/app/assets/javascripts/ui_models/application.ts @@ -189,13 +189,14 @@ export class WebApplication extends SNApplication { this.applicationElement.append(el); } - presentRevisionPreviewModal(uuid: string, content: any) { + presentRevisionPreviewModal(uuid: string, content: any, title?: string) { const scope: any = this.scope!.$new(true); scope.uuid = uuid; scope.content = content; + scope.title = title; scope.application = this; const el = this.$compile!( - `` )(scope); this.applicationElement.append(el); diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 8cb4c3559..822c4d50e 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -105,6 +105,7 @@ class EditorViewCtrl extends PureViewCtrl { public editorValues: EditorValues = { title: '', text: '' }; onEditorLoad?: () => void; + private scrollPosition = 0; private removeAltKeyObserver?: any; private removeTrashKeyObserver?: any; private removeTabObserver?: any; @@ -131,6 +132,8 @@ class EditorViewCtrl extends PureViewCtrl { this.editorMenuOnSelect = this.editorMenuOnSelect.bind(this); this.onPanelResizeFinish = this.onPanelResizeFinish.bind(this); + this.setScrollPosition = this.setScrollPosition.bind(this); + this.resetScrollPosition = this.resetScrollPosition.bind(this); this.onEditorLoad = () => { this.application!.getDesktopService().redoSearch(); }; @@ -868,6 +871,20 @@ class EditorViewCtrl extends PureViewCtrl { }); } + setScrollPosition() { + const editor = document.getElementById( + ElementIds.NoteTextEditor + ) as HTMLInputElement; + this.scrollPosition = editor.scrollTop; + } + + resetScrollPosition() { + const editor = document.getElementById( + ElementIds.NoteTextEditor + ) as HTMLInputElement; + editor.scrollTop = this.scrollPosition; + } + onSystemEditorLoad() { if (this.removeTabObserver) { return; @@ -915,6 +932,9 @@ class EditorViewCtrl extends PureViewCtrl { }, }); + editor.addEventListener('scroll', this.setScrollPosition); + editor.addEventListener('input', this.resetScrollPosition); + /** * Handles when the editor is destroyed, * (and not when our controller is destroyed.) @@ -922,6 +942,9 @@ class EditorViewCtrl extends PureViewCtrl { angular.element(editor).one('$destroy', () => { this.removeTabObserver?.(); this.removeTabObserver = undefined; + editor.removeEventListener('scroll', this.setScrollPosition); + editor.removeEventListener('scroll', this.resetScrollPosition); + this.scrollPosition = 0; }); } } diff --git a/app/assets/javascripts/views/notes/notes_view.ts b/app/assets/javascripts/views/notes/notes_view.ts index e59300f28..6ed9e41c1 100644 --- a/app/assets/javascripts/views/notes/notes_view.ts +++ b/app/assets/javascripts/views/notes/notes_view.ts @@ -216,7 +216,7 @@ class NotesViewCtrl extends PureViewCtrl { break; case ApplicationEvent.CompletedFullSync: this.getMostValidNotes().then((notes) => { - if (notes.length === 0 && this.selectedTag?.isAllTag) { + if (notes.length === 0 && this.selectedTag?.isAllTag && this.state.noteFilter.text === '') { this.createPlaceholderNote(); } }); diff --git a/app/assets/templates/directives/revision-preview-modal.pug b/app/assets/templates/directives/revision-preview-modal.pug index 339d4a2ba..ee0895408 100644 --- a/app/assets/templates/directives/revision-preview-modal.pug +++ b/app/assets/templates/directives/revision-preview-modal.pug @@ -5,7 +5,11 @@ .sn-component .sk-panel .sk-panel-header - .sk-panel-header-title Preview + div + .sk-panel-header-title Preview + .sk-subtitle.neutral.mt-1( + ng-if="ctrl.title" + ) {{ctrl.title}} .sk-horizontal-group a.sk-a.info.close-button( ng-click="ctrl.restore(false)"