Commit Graph

292 Commits (71ff5248fef842c7aa129913ebb1ef49da1aec10)

Author SHA1 Message Date
Bruno Windels d8bb9ecedf bring insert method inline with transform callback, add docs
before the insertPartsAt method would call the update callback
on its own, but now we have the concept of a transformation session,
so lets bring the API in line
2019-08-27 16:43:05 +02:00
Bruno Windels 8e66d382de don't crash on race with room members and initial composer render
not ideal, but for now this prevents a crash at startup
when a user-pill is persisted in local storage
2019-08-27 16:43:05 +02:00
Bruno Windels e0ec827a64 extra docs 2019-08-27 16:43:05 +02:00
Bruno Windels 68c2bb7ca6 introduce `transform` method so update can be called with a position
and also for multiple transformations at once. This removes
the need to call the update callback from `replaceRange()` as well
2019-08-27 16:43:05 +02:00
Bruno Windels f76a23d5dd return promise from updating autocomplete
so one can await if needed
2019-08-27 16:43:05 +02:00
Bruno Windels 0f6465a1db don't close autocomplete when hitting tab
that's not what the slate impl does and it's not an improvement
2019-08-27 16:43:05 +02:00
Bruno Windels 713205e0ab close autocomplete when removing auto-completed part 2019-08-27 16:43:05 +02:00
Bruno Windels f10e1d7654 fix jsdoc comments 2019-08-27 09:54:13 +02:00
Bruno Windels 5c28b57681 always recalculate position after doing transform step
as the amount of characters might not have changed,
parts may still have been merged, removed or added which
requires a new position.
2019-08-27 09:49:22 +02:00
Bruno Windels 4fd4ad41c1 improve editor model documentation 2019-08-26 16:16:27 +02:00
Bruno Windels f8f0e77bde add transform step during editor model update 2019-08-26 16:16:27 +02:00
Bruno Windels 0e65f71a37 support incrementing/decrementing doc positions with predicate 2019-08-26 16:16:27 +02:00
Bruno Windels 10291bafe0 add support for selecting ranges in the editor model, and replacing them
this to support finding emoticons and replacing them with an emoji
2019-08-26 16:16:27 +02:00
Bruno Windels 5cebce9bbf fix bug detected by tests 2019-08-22 14:41:40 +01:00
Bruno Windels e2dfe888cc only capture Enter when autocompletion list has selection
this is the old behaviour and makes sense IMO
also close the auto complete when resetting the composer model,
in case it was still open
2019-08-22 13:33:20 +01:00
Bruno Windels c5cd8b943a support auto complete for /commands 2019-08-22 13:33:20 +01:00
Bruno Windels 88cc1c428d add support for emotes and running /commands
this does not yet include autocomplete for commands
2019-08-22 13:33:20 +01:00
Bruno Windels 9bc8ff7e1e clear composer undo history when sending a message 2019-08-22 13:33:20 +01:00
Bruno Windels 0adca10f9f make named options argument optional 2019-08-22 13:33:20 +01:00
Bruno Windels 10c218825b allow inserting multiple parts at a position 2019-08-22 13:33:20 +01:00
Bruno Windels ce44c651d0 keep deserialized parts compatible with part api,
to avoid breakage when passing real parts
2019-08-22 13:33:20 +01:00
Bruno Windels d4fbe7ed69 make editor event parsing suitable for parsing messages to be quoted 2019-08-22 13:33:20 +01:00
Bruno Windels c135cd60d2 restore insert mention
for this, we need to store the last caret in the editor,
to know where to insert the user pill.

Because clicking on a member blurs the editor, and the
selection is moved away from the editor.

For this reason, we keep as cache of the last caretOffset object,
invalidated by a selection with different values.

The selection needs to be cloned because apparently the browser
mutates the object instead of returning a new one.
2019-08-22 13:33:20 +01:00
Bruno Windels f9992a1fc6 implement editor placeholder 2019-08-22 13:33:20 +01:00
Bruno Windels d22745a5b2 make it obvious arguments are optional
because now they have a setter
2019-08-22 13:33:20 +01:00
Bruno Windels 063eabed71 don't return invalid indices from model, fix for #10358 2019-08-22 13:33:20 +01:00
Bruno Windels 299cf8542c Split MessageEditor in edit-specifics & reusable part for main composer 2019-08-05 15:31:18 +02:00
Bruno Windels c53708b245 set lastNode directly when not decending 2019-08-02 16:36:09 +02:00
Bruno Windels af3eebd0a6 add undo steps after word boundary (or capped) when typing or removing 2019-08-02 11:31:01 +02:00
Bruno Windels 07b2e51dce put max step length in constant 2019-08-01 16:27:17 +02:00
Bruno Windels abde8b45d2 fix bug that prevented a line from being removed when undoing a newline 2019-08-01 11:28:40 +02:00
Bruno Windels 234404e598 add mod+z/y shortcuts, set editor state to what history manager returns 2019-08-01 11:27:09 +02:00
Bruno Windels 98bc0d24f4 push changes to history manager 2019-08-01 11:26:20 +02:00
Bruno Windels aa22c90f2c HistoryManager + unit tests 2019-08-01 11:25:04 +02:00
Bruno Windels a999acbd04 fix argument order 2019-07-30 17:17:25 +02:00
Bruno Windels 44e4661198 document return type 2019-07-30 12:34:30 +02:00
Bruno Windels 0b92077bba tests for turning caret position from model into dom position 2019-07-25 18:38:00 +02:00
Bruno Windels f8e1977f0a remove dead code 2019-07-25 14:50:20 +02:00
Bruno Windels 9bfba9db3e make PartCreator a bit more testable by not asking for deps of dep 2019-07-25 14:50:20 +02:00
Bruno Windels 419c800167 add tests for diffAtCaret 2019-07-25 14:50:20 +02:00
Bruno Windels 595dc82543 unit test + fixes + comments + simplication for diffDeletion 2019-07-25 14:50:20 +02:00
Bruno Windels 3753e5261d Implement diffing html messages in the edit history 2019-07-24 11:28:56 +02:00
Bruno Windels ee9dd8ce81 adjust jsdoc 2019-07-12 10:06:38 +02:00
Bruno Windels dedf978948 prevent inserting parts at index -1 for empty documents 2019-07-11 18:46:56 +02:00
Bruno Windels 06fb892df9 prevent autocomplete when doing bulk insertion (paste, drop text) 2019-07-11 18:46:56 +02:00
Bruno Windels f6e71b2335 turn flag into options object 2019-07-08 16:55:56 +02:00
Bruno Windels 888e4d1ec2 preserve reply fallback when editing 2019-07-08 15:25:44 +02:00
Bruno Windels 1c7af38d83
Merge pull request #3126 from matrix-org/bwindels/caret-refactoring
Editor caret improvements
2019-06-21 15:02:41 +00:00
Bruno Windels c443dd7a32 clarify why use a BOM marker for the caret nodes 2019-06-21 16:37:29 +02:00
Bruno Windels 503d702f47 take list nesting into account for indenting 2019-06-21 11:40:27 +02:00
Bruno Windels da766b8cba caretNode is a better className 2019-06-21 11:21:38 +02:00
Bruno Windels c5c987f62e use BOM marker instead of ZWS
that's what others do ...
2019-06-21 11:21:13 +02:00
Bruno Windels 366a4aa308 put zero-width spaces in caret nodes so chrome doesn't ignore them
this requires an update of the editor DOM > text & caret offset logic,
as the ZWS need to be ignored.
2019-06-20 14:44:18 +02:00
Bruno Windels f0271b593d remove special casing for moving caret after newline and pills
not needed anymore with new caret logic and having caret nodes
2019-06-19 17:42:18 +02:00
Bruno Windels a229641985 use caret nodes in caret positioning code, to move caret out of pills 2019-06-19 17:42:18 +02:00
Bruno Windels 607fc328ed also process first part when processing empty and mergeable parts
this was preventing clearing an emtpy plain part when inserting
a pill-candidate at the beginning of the model, which
prevented a caret node from being inserted before the pill.
2019-06-19 17:42:18 +02:00
Bruno Windels 75fc769742 insert "caret nodes" where pills don't have an adjacent text node
just empty spans, where the caret can be placed.
2019-06-19 17:42:18 +02:00
Bruno Windels 1db505c667 comment typo 2019-06-18 09:50:31 +02:00
Bruno Windels 3119feaa17 whitespace 2019-06-18 09:48:25 +02:00
Bruno Windels 47579f37e8 clarify why its always safe to not append @room at end while parsing 2019-06-18 08:40:58 +02:00
Bruno Windels d9e62b54fc also support deserializing at-room-pill when transferring editor state 2019-06-14 18:42:30 +02:00
Bruno Windels 78971f168f create AtRoomPill when autocomplete returns @room 2019-06-14 18:28:44 +02:00
Bruno Windels 65d56d1490 transform @room to AtRoomPill while deserializing html to md 2019-06-14 18:28:44 +02:00
Bruno Windels 63b11f5001 (de)serialize at-room-pills just like pill-candidate (no html needed) 2019-06-14 18:28:44 +02:00
Bruno Windels dfec5058c5 support creating @room pills in partcreator 2019-06-14 18:28:44 +02:00
Bruno Windels eb4ff50c3c do parts creation only in PartCreator to not scatter dependencies 2019-06-14 18:28:44 +02:00
Bruno Windels 3cfdd518ee detect emote when sending (and trim "/me " for content) 2019-06-14 11:02:20 +02:00
Bruno Windels aecfbce55c prepend "/me " to emotes when parsing them to edit 2019-06-14 11:01:52 +02:00
Bruno Windels 48f5cf1523
Merge pull request #2966 from npny/npny/autocomplete-arrow-keys
Allow arrow keys navigation in autocomplete list
2019-06-13 15:38:36 +00:00
Bruno Windels d40f49e2c2 fix lint 2019-06-12 19:09:27 +02:00
Bruno Windels 41e41269dc use EditorStateTransfer to pass on state to newly mounted editor 2019-06-12 18:52:34 +02:00
Bruno Windels e674f39e3b support (de)serializing parts with other dependencies than text 2019-06-12 18:32:32 +02:00
Pierre Boyer 8158567640 Remove left/right autocomplete navigation for MessageEditor 2019-06-05 10:49:49 +02:00
Pierre Boyer a4dec88c65 Add back on..Arrow functions. Add left/right key navigation in MessageEditor 2019-06-04 13:57:15 +02:00
Pierre Boyer ed6427571e Update src/editor/autocomplete to correctly call countCompletions and moveSelection 2019-06-04 13:24:24 +02:00
Bruno Windels 2d8c523642
Merge pull request #3040 from matrix-org/bwindels/editor-remaining-md
Fix: better HTML > MD conversion for editing, including lists and quotes
2019-05-31 09:21:43 +00:00
Bruno Windels 78fbea307c less escaping for backticks 2019-05-31 11:06:15 +02:00
Bruno Windels eb8dd52437
Merge pull request #3029 from matrix-org/bwindels/pill-n-newlines
Fix: maintain caret at current line when position is on newline part
2019-05-31 08:44:02 +00:00
Bruno Windels 686045b46a rewrite HTML>MD conversion,handle (nested) block elements&quotes better
Re-use walkDOMDepthFirst we already had for turning the editor into
a string, which also allows us to detect when leaving a node better,
which is needed to decide how block elements create newline parts
is more centralized and robust manner, more in line with
how html works (consecutive block elements break the line)
instead of hacky special casing from before.

Also, to support every line of MD generated
within a BLOCKQUOTE, the parts an element creates are returned
and then centrally prepended with "> ", instead of passing in
the parts array and doing it in every parse... function.
2019-05-29 14:46:15 +02:00
Bruno Windels b0d87e7e47 allow enterNodeCallback to decide whether to decend into a node 2019-05-29 14:27:36 +02:00
Bruno Windels 6b680ff681 fallback to setting caret on line node for empty lines
instead of setting at the end of the editor
2019-05-28 10:34:29 +02:00
Bruno Windels 4fc23022f4 remove all non-first-br nodes on new empty line, not just first one
nextSibling returned null after calling removeNode,
so get the nextSibling first
2019-05-28 10:01:16 +02:00
Bruno Windels 080a6301b1
Merge pull request #3032 from matrix-org/bwindels/filterreply
Message editing: fix reply text appearing in edit
2019-05-27 15:12:18 +00:00
Bruno Windels f5da8162c1 filter out reply text when editing 2019-05-27 17:04:26 +02:00
Aaron Raimist fec5abadd6
Message editing: preserve strikethrough as well
Signed-off-by: Aaron Raimist <aaron@raim.ist>
2019-05-24 13:57:09 -05:00
Bruno Windels b2592583c4 maintain caret at current line when position is on newline part 2019-05-24 18:54:29 +02:00
Bruno Windels 8c0b8ff618 take part length into account as well 2019-05-24 15:43:55 +02:00
Bruno Windels 9d6a818591
Merge pull request #3024 from matrix-org/bwindels/autocomplete-tab
Message editing: tab completion
2019-05-24 13:29:10 +00:00
Bruno Windels cf5e4d3d94 make consecutive :/@/# separate pill candidates
e.g. accept the first character always to start the autocompletion
but after that refer to the plainpart logic to split up in
new pill candidates. Also, don't allow merging adjacent parts.

This makes sure that "@nonmatchingfoo @someuser"
only matches "someuser" in the autocomplete.
2019-05-24 12:38:19 +02:00
Bruno Windels a024fd8991 port tab completion from MessageComposerInput 2019-05-24 12:38:01 +02:00
Bruno Windels 23465c696f dont jump to next part when inserting at *start* of uneditable part 2019-05-24 10:08:47 +02:00
Bruno Windels 723086e4d7 Decend into P & DIV elements while parsing a message.
Also split on newline so all newlines are represented by a newlinepart
2019-05-22 16:19:07 +02:00
Bruno Windels 5f5a2f7140 put code block on new line 2019-05-22 16:19:07 +02:00
Bruno Windels 53b6586986 re-apply markdown when saving a message 2019-05-22 16:19:07 +02:00
Bruno Windels 5373007301 initial attempt at converting html back to markdown 2019-05-22 16:18:35 +02:00
Bruno Windels ff61376c07
Merge pull request #3004 from matrix-org/bwindels/update-link-previews-after-edit
Message editing: update link previews after editing
2019-05-22 14:17:34 +00:00
Bruno Windels 6b1134bdf0 add matrix foundation copyright header 2019-05-22 16:16:32 +02:00
Bruno Windels fb03b5b168 fix lint 2019-05-21 13:49:43 +02:00
Bruno Windels a75c948e2e don't cache DRP 2019-05-21 12:24:12 +02:00
Bruno Windels 5d184b3f77 reuse mx_Pill styles for editor pills to avoid style duplication
the avatar style code is still different though,
as it's implemented differently

This also prevents updating the css variables when not needed,
which caused the avatar to flicker when updating the editor.
2019-05-21 12:19:35 +02:00
Bruno Windels df4f380082 find room by alias in room pill 2019-05-20 15:34:15 +02:00
Bruno Windels 0e98b124ac undo thinko of passing current room as pill room 2019-05-20 15:33:54 +02:00
Bruno Windels c1b2f3dce1 make user pill avatars work in editor 2019-05-20 14:21:25 +02:00
Bruno Windels 3b598a1782 set pill avatar through css variables to set on psuedo-element
this way it won't interfere with editor selection/caret
2019-05-20 10:28:26 +02:00
Bruno Windels 710338c01f pass member and room to editor pills to get avatar url 2019-05-20 10:28:26 +02:00
Bruno Windels 690ee63bb4 prevent zero-length removals from deleting uneditable parts
This solves an issue where, when backspacing the proceeding character next to a pill,
chrome reports the caret as being in the pill node, not at
the start of the proceeding text node. This would cause the pill
to be removed together with proceeding character.

This is a bug in any case, removing 0 characters
shouldn't remove the part
2019-05-16 19:14:24 +01:00
Bruno Windels 245f48a22c set caret on mount as we usually do, so FF doesn't enter 2 newlines 🤯 2019-05-16 18:39:20 +01:00
Bruno Windels 98e033a529 don't allow newline parts of longer than one newline 2019-05-16 18:13:48 +01:00
Bruno Windels f27607a74c don't put cursor position in NewlinePart after adding it
You can't append to it anyway, so mark it uneditable and skip
uneditable parts if that's where an edit ended up.

This has the added advantage that if there is text after a newly
insert pill, the cursor will be put just before it rather than
in the pill, after the last character.
2019-05-16 17:58:22 +01:00
Bruno Windels 5805a88ab9 adjust to js-sdk changes of marking original event as replaced 2019-05-15 11:54:26 +01:00
Bruno Windels d83e278f6b PR feedback, cleanup 2019-05-15 09:46:08 +01:00
Bruno Windels fd31e793d1 fix lint 2019-05-14 15:49:53 +01:00
Bruno Windels e2388afb51 consistent naming between serialize and deserialize modules 2019-05-14 15:39:24 +01:00
Bruno Windels 34dbe5f314 add newline parts for text messages as well 2019-05-14 15:38:16 +01:00
Bruno Windels 3abdf6b100 also serialize to text and method to tell us if we need html for model 2019-05-14 15:38:16 +01:00
Bruno Windels 2fbe73e658 draft of formatting 2019-05-14 15:38:16 +01:00
Bruno Windels eaf43d7277 correctly parse BRs 2019-05-14 15:38:16 +01:00
Bruno Windels c44fed4bea even less logging 2019-05-14 15:38:16 +01:00
Bruno Windels a3b02cf0cc make logging quiet 2019-05-14 15:38:16 +01:00
Bruno Windels 9e0816c51c find caret offset and calculate editor text in same tree-walking algo
instead of having the same logic twice
2019-05-14 15:38:16 +01:00
Bruno Windels 7ebb6ce621 WIP commit, newlines sort of working 2019-05-14 15:38:16 +01:00
Bruno Windels 9f597c7ec0 no comment nodes without react,so can bring this back to simpler version 2019-05-14 15:38:16 +01:00
Bruno Windels 7a85dd4e61 after completion, set caret in next part at start
instead of end of current part
2019-05-14 15:38:16 +01:00
Bruno Windels 2c3453d307 put caret after replaced part if no caretOffset is given by autocomplete 2019-05-14 15:38:16 +01:00
Bruno Windels 1a577eed11 take non-editable parts into account for new caret position 2019-05-14 15:38:16 +01:00
Bruno Windels 580a89875a fix autocompl. not always appearing/being updated when there is no part 2019-05-14 15:38:16 +01:00
Bruno Windels bc14d4f58f comment 2019-05-14 15:38:16 +01:00
Bruno Windels 22587da5ff close autocomplete on enter 2019-05-14 15:38:16 +01:00
Bruno Windels ffff66a92d handle Escape properly
close autocomplete, and also replace with plain text part.

also remove leftover logging
2019-05-14 15:38:16 +01:00
Bruno Windels 64b171198c rerender through callback instead of after modifying model
this way rendering is centralized and we can better rerender
from interaction in the autocompleter
(we didn't have access to caret before)
2019-05-14 15:38:16 +01:00
Bruno Windels aa1b4bb91e keep auto complete code close to each other 2019-05-14 15:38:16 +01:00
Bruno Windels 5e6367ab57 basic support for non-editable parts
e.g. pills, they get deleted when any character of them is removed
later on we also shouldn't allow the caret to be set inside of them
2019-05-14 15:38:16 +01:00
Bruno Windels 4bb8b79942 initial auto complete wrapper, make existing autocompleter work w/ model 2019-05-14 15:38:16 +01:00
Bruno Windels bb73521f0c prefer textContent over innerText as it's faster
and transforms the text less
2019-05-14 15:38:16 +01:00
Bruno Windels 1330b438d6 initial support for auto complete in model and parts
also move part creation out of model, into partcreator, which
can then also contain dependencies for creating the auto completer.
2019-05-14 15:38:16 +01:00
Bruno Windels a2f1f49972 update the DOM manually as opposed through react rendering
react messes up the DOM sometimes because of, I assume, not
being aware of the changes to the real DOM by contenteditable.
2019-05-14 15:38:16 +01:00
Bruno Windels 85adc8953f remove logging 2019-05-14 15:38:16 +01:00
Bruno Windels 0f38753dba some comments 2019-05-14 15:38:16 +01:00
Bruno Windels 8f0074f824 ignore react comment nodes when locating/setting caret 2019-05-14 15:38:16 +01:00
Bruno Windels 6be6492cd2 initial parsing of pills for editor 2019-05-14 15:38:16 +01:00
Bruno Windels 76bb56a2bf initial hookup editor code with react component 2019-05-14 15:38:16 +01:00
Bruno Windels 9f98a6c0e6 add converted prototype code 2019-05-14 15:38:16 +01:00