mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
scroll beyond last line in text/code editor, fixes #2728
This commit is contained in:
parent
90255ac55b
commit
0e16e48db6
@ -78,6 +78,7 @@ import HideFloatingButtonsButton from "../widgets/floating_buttons/hide_floating
|
||||
import ScriptExecutorWidget from "../widgets/ribbon_widgets/script_executor.js";
|
||||
import MovePaneButton from "../widgets/buttons/move_pane_button.js";
|
||||
import UploadAttachmentsDialog from "../widgets/dialogs/upload_attachments.js";
|
||||
import ScrollPaddingWidget from "../widgets/scroll_padding.js";
|
||||
|
||||
export default class DesktopLayout {
|
||||
constructor(customWidgets) {
|
||||
@ -173,6 +174,7 @@ export default class DesktopLayout {
|
||||
.child(new NoteListWidget())
|
||||
.child(new SearchResultWidget())
|
||||
.child(new SqlResultWidget())
|
||||
.child(new ScrollPaddingWidget())
|
||||
)
|
||||
.child(new ApiLogWidget())
|
||||
.child(new FindWidget())
|
||||
|
@ -142,7 +142,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
||||
this.$widget.toggleClass("full-height",
|
||||
(
|
||||
!this.noteContext.hasNoteList()
|
||||
&& ['editableText', 'editableCode', 'canvas', 'webView', 'noteMap'].includes(this.type)
|
||||
&& ['canvas', 'webView', 'noteMap'].includes(this.type)
|
||||
&& this.mime !== 'text/x-sqlite;schema=trilium'
|
||||
)
|
||||
|| this.noteContext.viewScope.viewMode === 'attachments'
|
||||
@ -191,12 +191,27 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
||||
}
|
||||
|
||||
async focusOnDetailEvent({ntxId}) {
|
||||
if (this.noteContext.ntxId === ntxId) {
|
||||
await this.refresh();
|
||||
if (this.noteContext.ntxId !== ntxId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const widget = this.getTypeWidget();
|
||||
await widget.initialized;
|
||||
widget.focus();
|
||||
await this.refresh();
|
||||
const widget = this.getTypeWidget();
|
||||
await widget.initialized;
|
||||
widget.focus();
|
||||
}
|
||||
|
||||
async scrollToEndEvent({ntxId}) {
|
||||
if (this.noteContext.ntxId !== ntxId) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.refresh();
|
||||
const widget = this.getTypeWidget();
|
||||
await widget.initialized;
|
||||
|
||||
if (widget.scrollToEnd) {
|
||||
widget.scrollToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
||||
this.$container = this.$widget.find(".note-map-container");
|
||||
this.$styleResolver = this.$widget.find('.style-resolver');
|
||||
|
||||
new ResizeObserver(() => this.setDimensions()).observe(this.$container[0])
|
||||
new ResizeObserver(() => this.setDimensions()).observe(this.$container[0]);
|
||||
|
||||
this.$widget.find(".map-type-switcher button").on("click", async e => {
|
||||
const type = $(e.target).closest("button").attr("data-type");
|
||||
|
@ -100,7 +100,7 @@ export default class NoteMapRibbonWidget extends NoteContextAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
new ResizeObserver(handleResize).observe(this.$widget[0])
|
||||
new ResizeObserver(handleResize).observe(this.$widget[0]);
|
||||
}
|
||||
|
||||
setSmallSize() {
|
||||
|
27
src/public/app/widgets/scroll_padding.js
Normal file
27
src/public/app/widgets/scroll_padding.js
Normal file
@ -0,0 +1,27 @@
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
|
||||
const TPL = `<div class="scroll-padding-widget"></div>`;
|
||||
|
||||
export default class ScrollPaddingWidget extends NoteContextAwareWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.contentSized();
|
||||
|
||||
this.$widget.on("click", () =>
|
||||
this.triggerCommand('scrollToEnd', {ntxId: this.ntxId}));
|
||||
}
|
||||
|
||||
initialRenderCompleteEvent() {
|
||||
this.$scrollingContainer = this.$widget.closest(".scrolling-container");
|
||||
|
||||
new ResizeObserver(() => this.refreshHeight()).observe(this.$scrollingContainer[0]);
|
||||
|
||||
this.refreshHeight();
|
||||
}
|
||||
|
||||
refreshHeight() {
|
||||
const containerHeight = this.$scrollingContainer.height();
|
||||
|
||||
this.$widget.css("height", Math.round(containerHeight / 2));
|
||||
}
|
||||
}
|
@ -110,6 +110,11 @@ export default class EditableCodeTypeWidget extends TypeWidget {
|
||||
this.codeEditor.focus();
|
||||
}
|
||||
|
||||
scrollToEnd() {
|
||||
this.codeEditor.setCursor(this.codeEditor.lineCount(), 0);
|
||||
this.codeEditor.focus();
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if (this.codeEditor) {
|
||||
this.spacedUpdate.allowUpdateWithoutChange(() => {
|
||||
|
@ -203,6 +203,14 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
||||
this.$editor.trigger('focus');
|
||||
}
|
||||
|
||||
scrollToEnd() {
|
||||
this.watchdog?.editor.model.change(writer => {
|
||||
writer.setSelection(writer.createPositionAt(this.watchdog?.editor.model.document.getRoot(), 'end'));
|
||||
});
|
||||
|
||||
this.watchdog?.editor.editing.view.focus();
|
||||
}
|
||||
|
||||
show() {}
|
||||
|
||||
getEditor() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user