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