Commit Graph
216 Commits
Author SHA1 Message Date
Philip Peitsch 26a9252edb Save and restore focus once per batch of operations
Focus saving and restoring is expensive on most browsers, so major gains
in performance are realised by not doing this for every operation. A new
pair of signals implemented by operation routers denotes when a batch of
operations is about to processed, and when the router has completed this
batch.

Note, there is no implied promises about how many operations are executed
within a batch. This is left as a choice to the router implementations.
2014-02-05 23:41:57 +11:00
Jos van den Oever 9e0059236d Add a general document interface for use in operations.
The UndoManager and TrivialUndoManager classes are adapted to the generalized interface.
2014-02-04 10:01:08 +01:00
Friedrich W. H. Kossebau 73b6f505cb clickStartedWithinContainer -> clickStartedWithinCanvas 2014-01-31 15:33:43 +01:00
Friedrich W. H. Kossebau d2671e2a00 @returns -> @return 2014-01-31 15:33:43 +01:00
Andreas Obergrusberger 45ebc8e02a Add ctrl+arrow per-word cursor movement 2014-01-30 21:33:39 +01:00
Philip Peitsch 34d1e37d21 Re-use session.enqueue to replay operations for the undo manager
An executing operation needs to emit various other signals (e.g.,
signalOperationStart) in order for various other controllers and UI
managers to perform correctly (e.g., preserving focus, re-drawing
the selection etc.).

The simplest way to ensure this happens is to use the session.enqueue
call. The UndoManager will ignore any new operations while performing
an undo.
2014-01-23 23:01:27 +11:00
lli 6e24de30f0 In edit mode, resets hyperlink cursor style to text whenever the editor got focus.
This prevents the cursor stays as hand icon in case user release the ctrl key after the editor lost focus.
2014-01-23 15:58:23 +11:00
lli 8cbe8b4afc Respond to ctrl key press event in edit mode only. 2014-01-23 14:52:47 +11:00
lli 2acd473a19 In edit mode, only open a hyperlink with Command+Click on MacOS
This matches the behaviour of LibreOffice.
2014-01-23 12:09:44 +11:00
lli 716e5bdc11 Disable the paragraph related styling methods if directParagraphStylingEnabled is false 2014-01-20 23:01:49 +11:00
lli 32f148930a Preserve the text style when splitting at the end of paragraph.
At the moment, splitting at the end of the following paragraph
<p style-name="standard">hello <span style-name="bold">world|</span></p>
will create a new paragraph like below
<p style-name="standard">|<span style-name="bold"></span></p>

The cursor is moved out of the span due to empty span is not considered as
a valid cursor position in the current design. this causes newly entered
text are not formatted correctly.

Merged DirectTextStyler and DirectParagraphStyler into
DirectFormattingController. These have become closely related concepts as
a result of changes in this patch.
2014-01-20 22:32:24 +11:00
Philip Peitsch b559fac679 Recapture focus after deleting an annotation 2014-01-16 17:30:31 +11:00
Philip Peitsch ea0dcf3cdc Recapture focus after clicking on an already selected image
Clicking on a selected image will lose the event trap focus. Focus needs
to be restored back to the event trap after this.
2014-01-16 17:06:43 +11:00
Aditya Bhatt 6921bffe71 Rename TextManipulator to TextController 2014-01-15 13:37:47 +05:30
Aditya Bhatt 1c65c0eeec Rename ImageManager to ImageController 2014-01-15 13:37:47 +05:30
Philip Peitsch 492fe5a409 Fix a performance regression when deleting large amounts of text
Having the event manager in focus during deletion causes text removal to
be approximately 3x slower.
2014-01-14 01:40:14 +11:00
Philip Peitsch 18312d6359 Only make the event trap editable if the document is in edit mode
Various browser menus (cut, delete) should only enable if the document
is currently in edit mode.
2014-01-10 20:58:15 +11:00
lli e2b7b378f1 Uses the previous selection style for the newly inserted character when replacing text 2014-01-09 22:01:40 +11:00
Philip Peitsch e2ec5af9d4 Don’t reset the undo manager state when entering or exiting edit mode
This allows consumers to enter and exit edit mode multiple times without
the undo stack being reset. Once the initial undo state has been captured
after the document is loaded, there is no major problems with preserving
the undo state (other than the undo manager’s shameful performance).
2014-01-08 21:48:32 +11:00
Philip Peitsch efe36bf4c0 Capture cursor registration for undo event even when not in edit mode
Any cursor add or removal commands should be tracked for the purposes
of restoring the document state. If a cursor operation is missed, the
document will not re-add the cursor after an undo operation.
2014-01-08 21:48:32 +11:00
Philip Peitsch 8de8dde612 Restore focus to the event trap if reset by an operation
With the event trap now being inside the cursor, any repositioning of
the cursor causes the document.activeElement and window selection to
change. This causes the document to stop being editable after actions
such as bolding current text.

Now, the focus state of the event trap is checked prior to each
operation, and will be reset back to the event trap if disrupted by an
operation. Note, checks are in place to prevent stealing focus if the
document is not active when an operation is executed.

Fixes issue #298
2014-01-08 21:32:10 +11:00
Philip Peitsch dabbd2739f Provide a mechanism for forcibly overriding a keybinding
SessionController needs to override the backspace key at all times, and
if the document is not editable, simply return true. The easiest way to
do this is to switch out the keybinding, and forcibly clobber the existing
keybinding when leaving edit mode.
2013-12-24 13:49:28 +11:00
Philip Peitsch 70dc7e5415 Annotations controller is always specified in a SessionController 2013-12-24 13:47:18 +11:00
Philip Peitsch 354056f68c Stop event trap from receiving focus on a mouse-down event
If the event trap receives focus on a mouse-down event, the selection will
become "trapped" inside the content-editable bounds. This can happen when
the user double-clicks on the caret (to start word expansion) and drags.
In this instance, the selection will appear to "stick" on the single word
surrounding the caret.

Problem introduced in 8b6ef8f
2013-12-24 00:48:20 +11:00
Philip Peitsch b17176ed34 Fix shift+click selection extending
If the current selection is inside the content editable event trap, attempting
to collapse the window selection will have no effect. This results in the
shift+click selection method just moving the cursor to the location of the
second click.

Problem introduced in 8b6ef8f
2013-12-24 00:48:20 +11:00
lli cde721f758 Updated the SessionController to use the same virtual selection in both edit and read only mode. 2013-12-19 10:39:42 +11:00
Friedrich W. H. Kossebau 432100d18c No longer needed to pass focus explicitely back for IE in synchronizeWindowSelection 2013-12-18 15:35:53 +01:00
Friedrich W. H. Kossebau a521f78304 Put custom data into drag handler instead of built-in nodes text extraction, concentrate mimedata export in new gui.MimeDataExporter 2013-12-18 15:12:22 +01:00
lli 66e25e096d Move selection related operations into the new SelectionController.js 2013-12-18 23:26:30 +11:00
Philip Peitsch 372485885a Workaround Safari post-composition key press event error
When composition session is ended on Safari under MacOS by pressing
another text char, Safari incorrectly reports the next keypress event’s
“which” value as the last compositionend data, rather than the new key
that was pressed.
2013-12-18 11:05:32 +11:00
Philip Peitsch 693702f332 Support back-to-back composition end & start events
Some IMEs will stack end & start requests back to back. If the selection
is modified between an old and new session (e.g., via text updates), the
new composition session never starts. One mainstream example of this is
inputting text using MacOS’s option+char method
2013-12-18 11:05:32 +11:00
Philip Peitsch 8b6ef8f6ff Support text input using the OS’s IME system
This change extends the use of the event trap to allow in-line character addition
using the OS's IME. The event trap will now be moved to within the local user's
cursor block, and will become visible when a composition start event is detected.

This has been tested on Chrome, FF & Safari on all platforms. In addition, this
enables support in FF on Android.

Known issues
- No IME support on Chrome under Linux. The compositionend event emitted by Chrome
contains no data, so the input character can't be detected.
2013-12-18 11:05:32 +11:00
Philip Peitsch c665b1a57f Workaround for Firefox selection.collapse bug
Attempting to collapse a selection if a content editable element is the
current activeElement for the document will cause the collapse call to
throw an exception.

https://bugzilla.mozilla.org/show_bug.cgi?id=773137
https://bugzilla.mozilla.org/show_bug.cgi?id=787305
2013-12-18 11:05:31 +11:00
lli dca79408b0 Hyperlink usability improvement
Current behaviour:
Left click causes navigation in both edit and view mode

After the change:
Same as current behaviour in view mode.
In edit mode, left click will just move the cursor to desired position. In order to navigate, user need to hold control key and then click
2013-12-17 17:59:17 +11:00
Philip Peitsch 9ed4ac0db4 Renamed HyperlinkManager to HyperlinkController 2013-12-13 23:35:51 +11:00
lli 05f41bac2f Added hyperlink support for text elements 2013-12-13 17:40:21 +11:00
Philip Peitsch 9642b9ffe0 Re-implement select-all behaviour using new StepsTranslator interfaces
This also addresses an outstanding TODO in code that select-all was only
ever selecting the entire document, rather than all the text inside the
current root (e.g., the current annotation)
2013-12-11 00:50:30 +11:00
Philip Peitsch 2ec3d857ec Re-implement the selection commands using new StepsTranslator interfaces
This re-implementation also addresses problems when navigating passed
annotations as identified in issue #65 & #65.

This also fixes a large performance issue with extending or moving the
cursor via short-cut keys.
2013-12-11 00:50:25 +11:00
Friedrich W. H. Kossebau ecf4d19c81 Clear more timeouts on call of destroy() methods 2013-12-06 14:31:41 +01:00
Philip Peitsch f56f474494 Reset the browser selection on drag end
A drag end will consume the corresponding mouse up operation, meaning
the window selection is not cleared. Cope with this by listening for
the drag event and clearing the selection.
2013-12-05 17:49:09 +11:00
Philip Peitsch a5173eaf71 Don't synchronize browser & WebODF selections unnecessarily
The window selection only needs to be synchronized with WebODF on a
mouse down operation. In all other cases, the selection doesn't need to
be maintained. Removing the selection most of the time significantly
helps performance as there is heavy costs to modifying part of a DOM
tree that is selected.

In order to allow cut/copy to continue to function, an event trap was
necessary that "holds" the selection after mouse-up. This is set as
content editable to allow the cut/copy events to be fired in Firefox and
Safari.
2013-12-05 17:35:42 +11:00
Philip Peitsch b77b99719d Reset selection to collapse on anchor when performing shift+click
Firefox seems to get rather confused about the window selection when
shift+extending it. Help this poor browser by resetting the window
selection back to the anchor node if the user is holding shift.

Fixes issue #123.
2013-11-30 01:18:28 +11:00
Philip Peitsch 93ba89b2d5 Expand to word and paragraph boundaries on mouse down
Previously, the editor would wait for mouse up before expanding the
virtual selection.

Now, this can easily be done on mouse down as well. this makes the
editor feel a lot more responsive when double or triple clicking to
increase expansion. It now mimics built-in Chrome behaviour.
2013-11-30 01:18:28 +11:00
Philip Peitsch bc7677af0e Don't allow paragraph selection to creep after mouse release
Chrome's built-in paragraph expansion will put the end of the selection
at (p,0) of the FOLLOWING paragraph. Round this back down to ensure the
next paragraph doesn't get incorrectly selected.

Fixes issue #165.
2013-11-30 01:18:28 +11:00
Philip Peitsch a662d7b2c6 Constrain anchor and focus nodes to the containing paragraph
This ensures that a cursor or selection remains within the
current paragraph container.

Fixes issue #161.
2013-11-30 01:17:54 +11:00
Philip Peitsch 5db32daa9d Ensure expand to word and paragraph boundaries keep selection direction
SessionController had some internal confusion about whether to work in
selection or range+bool. This cleans these up to ensure the direction is
properly preserved throughought.
2013-11-30 00:58:51 +11:00
Philip Peitsch 533c4d5681 Batch up multiple calls to redraw selection region
This does not need to be done immediately after every operation.
2013-11-30 00:54:05 +11:00
Jos van den Oever 3c96e17009 Make sure the cursor always has a Range. 2013-11-26 16:56:01 +01:00
Jos van den Oever 6e217df8a4 Better typechecking in SessionController and Namespaces. 2013-11-26 16:55:00 +01:00
Friedrich W. H. Kossebau 248e35ad8b Rename AnnotationManager to AnnotationController
also call do not call AnnotationViewManager objects not annotationManager
2013-11-19 19:56:15 +01:00