Skip to content

Commit

Permalink
Fix subtle anchor bug
Browse files Browse the repository at this point in the history
- webview was moving itself when scrolling to bottom anchors
  • Loading branch information
CalebJohn committed Mar 24, 2019
1 parent a6f19ea commit 8817d0d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 0 additions & 2 deletions ElectronClient/app/gui/note-viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@

let previousContentHeight = contentElement.scrollHeight;
let startTime = Date.now();
ignoreNextScrollEvent = true;
restorePercentScroll();

if (!checkScrollIID_) {
checkScrollIID_ = setInterval(() => {
const h = contentElement.scrollHeight;
if (h !== previousContentHeight) {
previousContentHeight = h;
ignoreNextScrollEvent = true;
restorePercentScroll();
}
if (Date.now() - startTime >= 1000) {
Expand Down
8 changes: 8 additions & 0 deletions ElectronClient/app/gui/note-viewer/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ window.addEventListener('message', (event) => {
const callName = event.data.name;
const args = event.data.args;

// HACK
// For some reason anchors at the bottom cause the webview to move itself
// so that the content is aligned with the top of the screen
// This basically refreshes the scroll view so that is returns to a normal
// position, the scroll positions stays correct though
if (callName === "percentScroll" && args[0] === 1)
location.hash = location.hash.split('#')[0]

if (args.length === 0) {
ipcRenderer.sendToHost(callName);
} else if (args.length === 1) {
Expand Down
6 changes: 3 additions & 3 deletions ElectronClient/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ElectronClient/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"markdown-it-multimd-table": "^3.1.3",
"markdown-it-sub": "^1.0.0",
"markdown-it-sup": "^1.0.0",
"markdown-it-toc-done-right": "^2.1.0",
"markdown-it-toc-done-right": "^3.0.1",
"md5": "^2.2.1",
"mime": "^2.3.1",
"moment": "^2.22.2",
Expand Down
2 changes: 1 addition & 1 deletion ReactNativeClient/lib/MdToHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MdToHtml {
markdownIt.use(rules.code_inline(context, ruleOptions));
markdownIt.use(markdownItAnchor)
if (Setting.value('plugin.toc'))
markdownIt.use(markdownItToc, { placeholder: '[[toc]]' })
markdownIt.use(markdownItToc, { listType: 'ul' })

for (let key in plugins) {
if (Setting.value('plugin.' + key))
Expand Down
2 changes: 1 addition & 1 deletion ReactNativeClient/lib/models/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class Setting extends BaseModel {
if (name === 'sync') return _('Synchronisation');
if (name === 'appearance') return _('Appearance');
if (name === 'note') return _('Note');
if (name === 'plugins') return _('Plugins');
if (name === 'plugins') return _('Plugins');
if (name === 'application') return _('Application');
return name;
}
Expand Down

0 comments on commit 8817d0d

Please sign in to comment.