0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00
Commit graph

488 commits

Author SHA1 Message Date
Neil Jenkins
e00a62e6fa Add comment to HTML on copy
This lets us detect on paste if the copy (probably) came from Squire.
2024-07-18 13:05:11 +10:00
Neil Jenkins
3def29e081 Fix merging text nodes after delete
startContainer is not necessarily a sibling to endContainer at this
point. endContainer is definitely at the right level of the hierarchy
so instead just get the previous sibling from this and merge with that
if it's also a text node.
2024-07-18 13:04:35 +10:00
Neil Jenkins
4156fb11d6 Reformat code to new prettier style 2024-07-17 15:26:08 +10:00
Neil Jenkins
077d29e778 Move range down tree for font info
This means if the selection is equivalent to just being inside a text
node, you'll get back the font info.

Resolves #462
2024-07-17 15:19:31 +10:00
Neil Jenkins
333d5fbd09 Remove ZWS and parent empty inlines on blur
Resolves #461
2024-07-17 15:18:27 +10:00
Neil Jenkins
d2e211796b Fix undo shortcut sometimes not working
Same deal - does the Shift modifier also modify the character? Just
allow both.

Fixes #457.
2024-03-04 11:22:10 +11:00
Neil Jenkins
46bc36861e Fix Shift-number shortcuts don't work on windows
The perennial issue of should keyboard shortcuts be about the character
or the key!
2024-03-04 10:52:07 +11:00
Chasen Stark
43799dc57d Editor.ts: Revert fix for Grammarly bug
The fix for Grammarly bug prevents pasting text directly from the keyboard on Android if the text to be
inserted contains \n, as pasting from the keyboard does not fire a true paste event. The Grammarly bug seems to have been
fixed in Samsung keyboard as of v5.6.10.4.
2024-02-22 13:28:17 -05:00
Illia Kyselov
4d2c80de92 fix(Editor): make willPaste custom event to be cancelable 2024-02-21 11:51:05 +11:00
Neil Jenkins
73e9d083dd Fix handling of Japanese IME input
With the modern keyboard events, the Backspace/Enter handlers were being
triggered even when they were part of an IME composition, which broke
the native IME handling. We now ignore all keyboard events that are part
of composition to avoid this issue.
2024-02-01 21:24:11 +11:00
Neil Jenkins
6cfd85bd8e Add undo point for automatic list creation
If you do `*` then space or `1. ` then space at the beginning of a line,
we automatically create a list. Now you can use undo to undo just the
automatic list creation, reverting to the plain text you typed.
2023-12-20 14:17:34 +11:00
Neil Jenkins
3804ea50ba Use modern keyboard event properties
The keyboard event handling code was written over a decade ago and we
have better APIs now! More importantly, the old APIs are deprecated, so
we should stop using them.

Fixes #450
2023-12-20 14:17:34 +11:00
Neil Jenkins
752a42d917 Fix Firefox cursor position bug after paste
We merge a faux block with contents from after a split point when
inserting HTML. The merge function presumes this block has already had
fixCursor run on it to ensure we add the <br>s some browsers need to
support correct cursor focusing.

Fixes #451
2023-12-20 14:17:34 +11:00
Neil Jenkins
c0479f3fdf Fix missing assignment in fixCursor
The parent variable was introduced in the Typescript refactor to make
the type checker happy, however we missed assigning the result back to
the `node` variable at the end.

Fixes #449
2023-12-20 10:45:19 +11:00
Chasen Stark
949b5b227e Editor.ts: Update insertText comment to address keyboard 'paste' bug 2023-11-30 13:09:40 -05:00
Neil Jenkins
efdff6c71b Focus editor after undo/redo
This matches the behaviour of all the other commands, and means if you
add toolbar buttons for undo/redo they work as expected.

Fixes #445.
2023-11-08 09:44:16 +01:00
Ioan Moldovan
ff7babcdd3 fix: invalid setKeyHandler key parameter type 2023-10-24 12:45:07 +11:00
Neil Jenkins
1ed32e3db7 Squire: Fix crash removing formatting
The fixer node may get removed when merging adjacent inlines, so move
the cleanup to before this. For safety, also properly check for non-null
nodes so we don't crash if it's still elided for some reason.
2023-10-09 11:52:58 +11:00
Neil Jenkins
57f2d37c1d Work around Chrome bug not rendering text
There seems to be a bug in Chrome where it will sometimes not render
some of the text in the DOM when there are multiple zero-width spaces
around the beginning and ends of inline tags (not sure on the exact
details).

Steps to reproduce (prior to this commit):

1. Turn on bold and underlined text
2. Type something in bold and underlined text
3. Turn off bold and underline
4. Try to type something — it will not show up! That is, until you press
   the enter key and we remove the zero-width spaces.
2023-10-04 12:28:38 +11:00
Neil Jenkins
cc32c7dd7e Fix empty string on clipboard if plainTextOnly
If extractRangeToClipboard was called with a toPlainText fn and
plainTextOnly=true, and there was a selection that was not just inside
a single text node, it was not actually getting the text to add to the
clipboard.
2023-10-03 11:13:02 +11:00
Neil Jenkins
950e122c5c Improve default plain text cut/copy
Instead of using innerText, this now uses the getTextContentsOfRange
helper fn to work out the white space, so is consistent with the
editor's getSelectedText method and should be higher fidelity.

Note, you can still override the behaviour by supplying a toPlainText
fn in the editor config (such as the one you can find at
https://github.com/fastmail/overture/blob/master/source/html/toPlainText.js)
2023-10-02 13:27:19 +11:00
Neil Jenkins
96e4bf2e98 Replace nbsp with regular sp when extracting text
The nbsp are used by the browser to stop HTML white space collapsing
from applying, but we don't want them in the plain text version.
2023-10-02 13:23:12 +11:00
Neil Jenkins
3937c10b55 Extract getTextContentsOfRange helper fn 2023-10-02 13:12:51 +11:00
Neil Jenkins
9aa62781d0 Add toPlainText config option
This allows you to customise how HTML you cut/copy in the editor is
converted into plain text.
2023-10-02 13:01:16 +11:00
Neil Jenkins
e324748f0f Remove obsolete execCommand calls
Firefox removed the need for this in v64.

Resolves #439.
2023-10-02 12:41:55 +11:00
Neil Jenkins
9f5df9e5c0 Fix format intent lost after pressing Space
On Chrome, if you made an inline formatting change, this would insert a
new <span> with a ZWS inside so we could focus it. Pressing Space would
remove this ZWS resulting in the focus ending up outside and so the
formatting would be lost. We were removing the ZWS so we could check
if we were at a block boundary correctly; instead, I've made it so the
boundary check can handle trailing or leading ZWS (see previous commit).
2023-09-27 14:56:00 +10:00
Neil Jenkins
2d37608aac Ignore ZWS when determining if at block boundary
These are just added to allow Chrome to focus an empty text node, but
they should not be considered "real" content.
2023-09-27 14:51:26 +10:00
Neil Jenkins
edde44a924 Auto-format list if starting line with * or 1. 2023-09-19 14:45:15 +08:00
Callum Skeet
c9f10b297b Make isPaste optional for Squire.insertHTML
This aligns the interface with the spec
2023-07-31 12:49:55 +10:00
Callum Skeet
a74ec739b9 Add autocomplete to config in Squire constructor 2023-07-31 12:49:15 +10:00
Callum Skeet
f1657acbc4 Export SquireConfig as type 2023-07-31 12:48:27 +10:00
Neil Jenkins
cbde45311a Fix crash linkifying text in middle of node
We were looking at the selection properties after we had mutated the DOM, and
trying to manipulate them based on some numbers cached from before mutating
the DOM, which could result in trying to set a negative index for the selection
offset. Instead, calculate all our values before we do any mutations.

Fixes #430
2023-04-20 10:57:05 +10:00
Neil Jenkins
8304fd3e04 Let ArrowRight key always break out of <code> 2023-02-22 16:01:23 +11:00
Neil Jenkins
cf30a69b89 Fix backspace can delete two characters
If we're handling the backspace completely ourselves, must prevent
default to stop the browser also having a go.
2023-02-22 11:27:16 +11:00
Neil Jenkins
137c8f0b17 Consistently focus after removeAllFormatting 2023-02-22 11:14:16 +11:00
Neil Jenkins
474847872c Use Array.from for older browser support 2023-02-22 11:13:38 +11:00
Neil Jenkins
4306cecb6e Remove multiple adjacent empty text nodes
Fix the loop condition so this will remove multiple adjacent empty
text nodes if necessary.
2023-02-20 10:17:56 +11:00
Neil Jenkins
9f258f2561 Code style fix 2023-02-20 09:46:56 +11:00
djmaze
cdb57ebda0 Don't use live NodeList 2023-02-20 09:34:59 +11:00
Neil Jenkins
1904405ab8 Auto delink if backspacing inside auto-linked URL
This means if you make a mistake and backspace, you don't end up
accidentally fixing the text but leaving the link to the wrong URL.
2023-02-01 14:20:53 +11:00
Neil Jenkins
b85754ca50 Handle empty nodes in moveRangeBoundariesDownTree
Empty text nodes next to another text node can always be safely
eliminated.
2023-02-01 14:19:52 +11:00
Neil Jenkins
e4ae7c2b81 Remove redundant <span> after replacing styles
It no CSS left after replacing with semantic equivalent, remove the
whole span.
2023-02-01 13:52:53 +11:00
Neil Jenkins
168033d25d Fix duplicate CSS created when replacing styles
When extracting the <span> CSS, a bug in refactoring meant we were not
removing it from the original node.
2023-02-01 13:52:11 +11:00
Joe Woods
00e3482815 Add secondary path if setBaseAndExtent undefined 2023-01-30 23:50:29 +00:00
Neil Jenkins
fe0dfdf6c4 Squire 2.0
This is a massive refactor to port Squire to TypeScript, fix a bunch of small
bugs and modernise our tooling. The development was done on an internal
repository, so apologies to anyone following externally for the commit dump;
updates from here should come as real commits again.

Co-authored-by: Joe Woods <woods@fastmailteam.com>
2023-01-23 13:18:29 +11:00
Limon Monte
c045ec0df5 allow leading tabs when pasting 2021-10-25 21:35:34 +11:00
Neil Jenkins
108ff8f475 Use sanitizeToDOMFragment fn for undo/redo
The content should be safe anyway as it will already have been sanitised,
however mXSS attacks are still a slight risk so safer to always run it through
the sanitiser.
2021-02-05 14:26:38 +11:00
Limon Monte
c6e2498639 support \ in setKeyHandler() 2021-02-02 15:36:02 +11:00
Limon Monte
a9d8e60714 support / in setKeyHandler() 2021-02-02 15:36:02 +11:00
djmaze
724611477d Bugfix: decreaseBlockQuoteLevel removed all levels 2020-09-09 16:29:34 +10:00