mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 14:52:19 +03:00
GH-339 Correct computation of in viewport
This commit is contained in:
parent
63b3a35ba9
commit
7953487c03
@ -291,7 +291,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
|
|||||||
|
|
||||||
fileprivate func scrollSubscription(source: Observable<Any>) -> Disposable {
|
fileprivate func scrollSubscription(source: Observable<Any>) -> Disposable {
|
||||||
return source
|
return source
|
||||||
.throttle(1, latest: true, scheduler: MainScheduler.instance)
|
.throttle(0.75, latest: true, scheduler: MainScheduler.instance)
|
||||||
.filter { $0 is MainWindowComponent.ScrollAction }
|
.filter { $0 is MainWindowComponent.ScrollAction }
|
||||||
.map { $0 as! MainWindowComponent.ScrollAction }
|
.map { $0 as! MainWindowComponent.ScrollAction }
|
||||||
.subscribe(onNext: { [unowned self] action in
|
.subscribe(onNext: { [unowned self] action in
|
||||||
@ -311,7 +311,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
|
|||||||
|
|
||||||
fileprivate func addReactions() {
|
fileprivate func addReactions() {
|
||||||
self.webviewMessageHandler.flow.sink
|
self.webviewMessageHandler.flow.sink
|
||||||
.throttle(1, latest: true, scheduler: MainScheduler.instance)
|
.throttle(0.75, latest: true, scheduler: MainScheduler.instance)
|
||||||
.filter { $0 is WebviewMessageHandler.Action }
|
.filter { $0 is WebviewMessageHandler.Action }
|
||||||
.map { $0 as! WebviewMessageHandler.Action }
|
.map { $0 as! WebviewMessageHandler.Action }
|
||||||
.subscribe(onNext: { [weak self] action in
|
.subscribe(onNext: { [weak self] action in
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
const rect = el.getBoundingClientRect();
|
const rect = el.getBoundingClientRect();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(rect.top >= 0 || (rect.top < 0 && rect.bottom > 0)) &&
|
((rect.top >= 0 && window.innerHeight - rect.top >= 0) || (rect.top < 0 && rect.bottom > 0)) &&
|
||||||
(rect.left >= 0 || (rect.left < 0 && rect.right > 0))
|
((rect.left >= 0 && window.innerWidth - rect.left >= 0) || (rect.left < 0 && rect.right > 0))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +71,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastMarkdownPosition = result;
|
lastMarkdownPosition = result;
|
||||||
|
// console.log(`webview scrolled to ${result.lineBegin}:${result.columnBegin}`);
|
||||||
window.webkit.messageHandlers.com_vimr_preview_markdown.postMessage(result);
|
window.webkit.messageHandlers.com_vimr_preview_markdown.postMessage(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,14 +117,19 @@
|
|||||||
}, Number.MAX_SAFE_INTEGER);
|
}, Number.MAX_SAFE_INTEGER);
|
||||||
|
|
||||||
const candidateEntry = entriesWithMinRowDistance.find(entry => entry.columnDistance == minColumnDistance);
|
const candidateEntry = entriesWithMinRowDistance.find(entry => entry.columnDistance == minColumnDistance);
|
||||||
|
|
||||||
if (!candidateEntry) {
|
if (!candidateEntry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {x, y} = scrollPosition(candidateEntry.element);
|
const element = candidateEntry.element;
|
||||||
|
if (isElementVisibleInViewport(element)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let {x, y} = scrollPosition(element);
|
||||||
suppressNextScrollEvent = true;
|
suppressNextScrollEvent = true;
|
||||||
window.scrollTo(x, y);
|
window.scrollTo(x, y);
|
||||||
|
// console.log(`scrolled webview to ${x}:${y}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollPosition(element) {
|
function scrollPosition(element) {
|
||||||
|
Loading…
Reference in New Issue
Block a user