mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
Move the cursor to the start of the annotation that has been removed
Moving the cursor to the start of the removed annotation allows the scrollIntoView behaviour to work more smoothly. Previously, removing an on- screen annotation would likely result in the view being reset to the cursor which was potentially offscreen at the time. Fixes issue #33
This commit is contained in:
committed by
Friedrich W. H. Kossebau
parent
4e7e440405
commit
90d67768d0
@@ -48,7 +48,8 @@ runtime.loadClass("gui.Caret");
|
||||
gui.CaretManager = function CaretManager(sessionController) {
|
||||
"use strict";
|
||||
var carets = {},
|
||||
window = runtime.getWindow();
|
||||
window = runtime.getWindow(),
|
||||
scrollIntoViewScheduled = false;
|
||||
|
||||
/**
|
||||
* @param {!string} memberId
|
||||
@@ -98,19 +99,29 @@ gui.CaretManager = function CaretManager(sessionController) {
|
||||
}
|
||||
}
|
||||
|
||||
function ensureCaretVisible() {
|
||||
var caret = getCaret(sessionController.getInputMemberId());
|
||||
if (caret && !scrollIntoViewScheduled) {
|
||||
caret.updateVerticalCaretAlignment(); // This is really noticeable if delayed. Calculate the cursor size immediately
|
||||
scrollIntoViewScheduled = true;
|
||||
// Delay the actual scrolling just in case there are a batch of operations
|
||||
// being performed. 50ms is close enough to "instant" that the user won't notice
|
||||
// the delay here.
|
||||
runtime.setTimeout(function() {
|
||||
scrollIntoViewScheduled = false;
|
||||
caret.ensureVisible();
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Object} info
|
||||
* @return {undefined}
|
||||
*/
|
||||
function ensureLocalCaretVisible(info) {
|
||||
var caret;
|
||||
|
||||
if (info.memberId === sessionController.getInputMemberId()) {
|
||||
// on member edit actions ensure visibility of cursor
|
||||
caret = getCaret(info.memberId);
|
||||
if (caret) {
|
||||
caret.ensureVisible();
|
||||
}
|
||||
ensureCaretVisible();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +182,7 @@ gui.CaretManager = function CaretManager(sessionController) {
|
||||
runtime.log("Starting to track input on new cursor of " + memberid);
|
||||
|
||||
// wire up the cursor update to caret visibility update
|
||||
cursor.handleUpdate = caret.ensureVisible;
|
||||
cursor.handleUpdate = ensureCaretVisible;
|
||||
// Pass event focus to the session controller
|
||||
sessionController.getEventManager().focus();
|
||||
} else {
|
||||
|
||||
@@ -437,7 +437,7 @@ gui.SessionController = (function () {
|
||||
* @return {undefined}
|
||||
*/
|
||||
function removeAnnotation(annotationNode) {
|
||||
var position, length, op;
|
||||
var position, length, op, moveCursor;
|
||||
|
||||
position = getFirstWalkablePositionInNode(annotationNode);
|
||||
length = getWalkableNodeLength(annotationNode);
|
||||
@@ -448,7 +448,13 @@ gui.SessionController = (function () {
|
||||
position: position,
|
||||
length: length
|
||||
});
|
||||
session.enqueue([op]);
|
||||
moveCursor = new ops.OpMoveCursor();
|
||||
moveCursor.init({
|
||||
memberid: inputMemberId,
|
||||
position: position-1, // Last position just before the annotation starts
|
||||
length: 0
|
||||
});
|
||||
session.enqueue([op, moveCursor]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user