Skip to content

Commit

Permalink
fix: 🐛 Less jarring scroll on copyLineUpOrDown
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Oct 30, 2021
1 parent 3df6c77 commit bb6e210
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare module "obsidian" {
wordAt: (offset: number) => { fromOffset: number; toOffset: number };
};
getDoc: () => Doc;
getScrollInfo: () => { top: number; left: number; clientHeight: number };
};
}

Expand Down
11 changes: 4 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import {
Constructor,
Editor,
EditorPosition,
EditorSelection,
EditorSelectionOrCaret,
ItemView,
Notice,
Plugin,
WorkspaceLeaf,
} from "obsidian";
import { openView, saveViewSide } from "obsidian-community-lib";
import type { ACSettings as ACSettings, Mode, Query } from "src/interfaces";
import SavedQView from "src/SavedQView";
import { cmdId, cmdName, createRegex } from "src/utils";
import { DEFAULT_SETTINGS, MODES, VIEW_TYPE_AC } from "./const";
import { CursorsModal } from "./CursorsModal";
import { ACSettingTab } from "./SettingTab";
import { openView, saveViewSide } from "obsidian-community-lib";

export default class ACPlugin extends Plugin {
settings: ACSettings;
Expand Down Expand Up @@ -146,10 +144,9 @@ export default class ACPlugin extends Plugin {
cursorTo.line += copyLines.length;
}
editor.setSelection(cursorFrom, cursorTo);
let [from, to] = [editor.getCursor("from"), editor.getCursor("to")];
editor.scrollIntoView({ from, to });
const { top, left } = editor.getScrollInfo();
editor.scrollTo(left, top + window.innerHeight / 2);
// @ts-ignore
const { top, left, clientHeight } = editor.getScrollInfo();
editor.scrollTo(left, top + clientHeight / 2);
}

matchToSel(editor: Editor, match: RegExpMatchArray, offset = 0) {
Expand Down

0 comments on commit bb6e210

Please sign in to comment.