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

492 commits

Author SHA1 Message Date
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
Neil Jenkins
19f73d162f Fix Android Chromium 85 closes keyboard on selection change
The previous workaround no longer works. You still can't use removeAllRanges
(that closes the keyboard too), but we can use the setBaseAndExtent API instead.
2020-09-02 15:39:29 +10:00
Neil Jenkins
c78bd4aac9 If text == html, only copy as plain text
It must be plain text if they're the same, and this helps avoid a Safari bug
(when we can) where when you copy HTML and then paste it in Pages/Numbers, it
gets the charset wrong and mangles non-ASCII characters.
2020-07-27 11:16:47 +10:00
Neil Jenkins
e46b2e4881 Only cleanupBrs on copy if using innerText
This is a fix for Firefox's inner text handling, so if we're not using that
don't bother.
2020-07-20 10:56:23 +10:00
Neil Jenkins
a91c3f3042 Always run html through willCutCopy fn
The plain text may be calculated from the HTML, so we should convert the
HTML first, then convert it to text.
2020-07-14 19:59:03 +10:00
Neil Jenkins
d5b320bd7d Fix plain text only copying when using toPlainText
We need to get the HTML to convert.
2020-07-14 19:57:32 +10:00
Nicholas Wylie
b952894d10 Export onCopy function 2020-07-14 13:33:48 +10:00
Neil Jenkins
73f18523a2 Remove unused variables 2020-07-14 12:12:45 +10:00
Nicholas Wylie
a3de6add71 Update shortcuts to toggle lists
Previously ctrl+shift+{7,8} would make an (un)ordered list but
hitting the shortcut again would have no effect. This change
causes the list to be removed when triggering the shortcut while
inside the list.
2020-06-25 16:00:06 +10:00
Nicholas Wylie
bb3cd05c64 Move cursor outside of <a> when inserting HTML
When links are pasted into the editor the cursor ends up at the
end of the text node inside the parent <a> element. Any text
entered is then appended to the end of the link text. Chrome
automatically moves the cursor after the end of <a> elements when
additional text is inserted, so this change enforces the same
behaviour in other browsers.

Resolves LP 55607264
https://app.liquidplanner.com/space/14822/projects/show/55607264
2020-06-04 15:02:03 +10:00
Nicholas Wylie
85e39333dc Map Cmd-[] to change list level when in list
These shortcuts alter the indentation level of blockquotes. When inside a list this is probably not the behaviour the user would expect. This change alters the functionality to increase/decrease the list indentation level instead of wrapping the list item in a blockquote when inside a list.

Co-authored-by: Neil Jenkins <neil@nmjenkins.com>
2020-05-19 14:45:05 +10:00
Neil Jenkins
6b3ce94406 Fix backspace sometimes not handled on mobile
With soft keyboards, e.g. on an iPhone, the shift key is automatically activated
when the cursor is at the beginning of the paragraph. However, this meant that
when you hit backspace, we were not handling the event and the browser was doing
it for us, resulting in broken styling.
2020-05-11 11:16:11 +10:00
Neil Jenkins
db4179cc39 Fix disabling Grammarly
How this underscore got there I don't know, *sigh*.
2020-04-29 12:18:35 +10:00
Neil Jenkins
1d03266b05 Disable Grammarly extension
The extension does not handle rich text inputs well at all and causes various
broken behaviour, such as weird line breaks.
2020-04-27 16:19:20 +10:00
Tim Gates
8cc1e34a6c docs: Fix simple typo, unfocussable -> unfocusable
There is a small typo in build/squire-raw.js, source/Node.js.

Should read `unfocusable` rather than `unfocussable`.
2020-04-14 21:50:33 +10:00
Neil Jenkins
e1e8ec78cb Remove uneditable container entirely on delete/backspace
If you backspace/delete to remove an uneditable block, we should be checking if
it's part of a larger uneditable container and if so removing the whole thing.
2020-03-29 13:42:15 +11:00
Neil Jenkins
07b459db3b Remove support for IE<11 2020-03-11 14:48:48 +11:00
Neil Jenkins
58321e5504 Remove support for pre-Chromium Opera 2020-03-11 14:47:14 +11:00
Neil Jenkins
b36a35faf4 Remove polyfill for FF3.5
That's way too old to support any more.
2020-03-11 14:36:30 +11:00
Neil Jenkins
e1f982a3dd Detect iOS when it's an iPad pretending to be a Mac 2020-03-11 14:35:50 +11:00
Neil Jenkins
2d307ba54a Fix first line of plain text paste not HTML escaped 2020-03-10 18:46:40 +11:00
Neil Jenkins
f6d6ac8ca0 Pasting plain text on a blank line should keep line's formatting 2020-03-02 10:23:24 +11:00
Neil Jenkins
ede1991931 Fix typo and whitespace issues 2020-03-02 10:21:23 +11:00
Neil Jenkins
c5a7c622fe Preserve target block formatting when pasting inline text
If you have a document like this:

<div style="font-size:20px">XXXX</div>
<div style="font-size:14px">YYYY</div>

and you select the YYYY text and copy it, we just copy the text to the clipboard
and not the block formatting. This is fine.

Now you select XXXX and paste. Because that removes all content from the first
block we were replacing it with the block formatting from the clipboard. But
this has no block formatting, so you essentially just "lost" the font-size:20px,
which broke user expectations.

(If the copied text *did* have block formatting, then replacing the block is
the correct thing to do in this case, which we still do.)
2020-02-24 14:50:22 +11:00
Neil Jenkins
2799f172ee Preserve all span attributes
When cleaning the span don't remove it, just remove the properties now going
into their own node.
2020-02-24 14:50:03 +11:00
Neil Jenkins
b550de09f0 Don't extract colour into separate <span>s
Because it's the parsed representation, you lose the comments in the
CSS so it breaks the dark mode reverse transform.
2020-02-24 14:49:48 +11:00
Neil Jenkins
8980c1ac4a Skip replacing node if type/class match
Replacing the node risks blatting other properties, so safer not to if it
already seems to be the right sort.
2020-02-24 14:49:30 +11:00
Neil Jenkins
9916a4c300 Improve link detection regexp.
Fixes the pathological handling of unmatched brackets, which could hang the
browser. Adds support for mailto: query params. Removes support for nested
parentheses in URLs, as these are rare. Adds comment with formatted version of
regex to make it easier to modify in future.
2020-02-24 14:48:46 +11:00
Neil Jenkins
f8a5b1ee19 Don't try to rewrite style of <p>
This was the only block-level element being rewritten, and could result in some
strange effects. For example, when you move a background colour from the <p> to
a <span>, it renders very differently. It was already inconsistent to do this
for <p> but not for <div>, and better just to drop it.
2020-02-24 14:47:33 +11:00
Neil Jenkins
af93577405 Clone all attributes when replacing tags
This makes it more likely to preserve the visual result.
2020-02-24 14:46:41 +11:00
Neil Jenkins
2cfba2cf1d Don' use default block style to replace <br>s
When converting <br>s to our preferred <div> style in fixContainer,
we don't want to use the default block style as that may change the
visual output. We always want to just use a basic <div>; the only
purpose is for line breaks.
2020-02-24 14:46:41 +11:00
Neil Jenkins
43646a062f Remove redundant property lookup
We already have it in a variable, just use that.
2020-02-24 14:46:41 +11:00
Limon Monte
1850e2cdae Add config.addLinks 2019-12-30 13:14:33 +11:00
Neil Jenkins
9218c9ba14 Fix iOS auto-capitalisation on enter 2019-11-20 22:52:36 +08:00
Neil Jenkins
dcd121a65a Ignore shift key on enter on iOS 2019-11-20 22:10:05 +08:00
Neil Jenkins
15f9b46728 Handle clipboard on iOS again
The WebKit bug (https://bugs.webkit.org/show_bug.cgi?id=143776) was fixed back
in iOS 11.4.

This reverts 3be9a7dea8.
2019-11-17 10:21:33 +08:00
Neil Jenkins
3dc4f201d9 Don't autoscroll on focus
If the rich text view is inside an overflow:scroll, every time you add a link
or do something else that requires we programatically focus the editor it would
jump the scroll back to the top; very annoying.
2019-09-25 20:49:56 -04:00
Neil Jenkins
6b85bda364 Handle pasting text/uri-list 2019-03-25 15:40:41 -04:00
Neil Jenkins
43b2c6b0e1 Insert table rather than image on paste from Excel 2019-02-21 16:31:06 +11:00
Neil Jenkins
2059c5a4ae Fix pasting image copied from browser 2019-01-10 15:18:24 +11:00
Neil Jenkins
892986b17c Don't crash removing list if no <li> inside 2018-10-19 11:54:05 +11:00
Neil Jenkins
5b998f5b6f Fix Kana-Kanji input on Mac Safari
Resolves #332
2018-10-15 08:40:10 +11:00
Neil Jenkins
79e65240bd Make detect-link regular expression customisable
Resolves #313
2018-10-05 17:00:09 +10:00
Neil Jenkins
b14ae45b38 Escape <a> on space even if in nested tags
Fixes #326
2018-10-05 16:25:28 +10:00
Neil Jenkins
9b654a82b1 Convert adjacent space to nbsp when extracting range
This resolves the issue where if you selected a word and then typed to replace
it, the following space would be deleted as well.

Fixes #331
2018-10-05 11:36:20 +10:00
Neil Jenkins
625d10139e Add support for <pre>/<code> formatting 2018-07-27 10:47:38 +10:00
Neil Jenkins
e07150192f Make shift-enter always just add <br> 2018-07-27 09:23:26 +10:00
Neil Jenkins
2d5114c669 Make TreeWalker filter argument optional 2018-07-27 09:22:06 +10:00
Neil Jenkins
e3e7c17315 Add config.willCutCopy option
Is an optional function that transforms the HTML being cut/copied before
placing it on the clipboard.
2018-07-12 15:40:01 +10:00
Neil Jenkins
f0594091c5 Allow class names to be configured 2018-07-12 15:22:18 +10:00
Neil Jenkins
7a24d6c505 Make check for link protocol case-insensitive
Resolves #308.
2018-06-23 14:39:59 +10:00
Neil Jenkins
35a25e6d44 Simplify regex for matching link query params 2018-06-23 14:35:16 +10:00
dhoko
10bf787651 Parse url and create anchor with queryparams 2018-06-23 14:21:46 +10:00
Neil Jenkins
db005b379b Make createRange method public 2018-05-09 17:43:11 +10:00
Neil Jenkins
389daab664 If ctrl/meta held down, key is not inserting text 2018-03-26 10:06:01 +01:00
Neil Jenkins
b0ac7d32d0 Handle all cases of overwriting content
Modern browsers tell you which character will be inserted with event.key, so
we can make sure we handle content deletion ourselves in these cases too.
2018-03-18 10:40:03 +00:00
Neil Jenkins
9dda7cc845 Fix FF does not leave <a> on space 2018-03-18 10:34:12 +00:00
Neil Jenkins
070f2e52a3 Support pasting images in Edge 2017-12-13 16:43:43 +11:00
Neil Jenkins
50fb7c7c53 Preserve block style if pasting on blank line
If the clipboard contains block contents, e.g.

<blockquote><p>Foo</p></blockquote>

Then if you paste it into a block that already has content we merge the inline
content from the first block and discard its surrounding block.

However, if you paste into an empty block, we'll now keep the block and remove
the empty one in the document. This seems a reasonable heuristic for determining
user intent.
2017-11-01 10:45:21 +11:00
Neil Jenkins
306230d0df Better handling of <pre>
* Pasting <pre> should not attempt to merge with block.
* Hitting enter should produce a new <pre>, otherwise all new lines after the
  break are lost.
2017-09-05 11:42:54 +10:00
Neil Jenkins
033370ebee Don't try to merge table cell into block on paste 2017-09-04 10:22:49 +10:00
Neil Jenkins
c5be1b79dc Fix broken variable reference 2017-08-17 14:12:29 +10:00
Neil Jenkins
833d7dfdbd New (increase|decrease)ListLevel algorithms
Fixes #287
2017-08-15 11:11:48 +10:00
Neil Jenkins
6842cb94eb Fix undo does not always restore cursor position.
If the content hasn't changed before an undo point is requested we ignore the
request, but the cursor position may have changed and users expect undo to
restore the cursor position immediately before the requested change was made.

So in this instance we now still record an undo state, but replace the previous
one if the content is unchanged.
2017-07-19 14:29:36 +02:00
Neil Jenkins
48fabd491a Improved algorithm for inserting tree into range
Fixes #283
2017-07-19 14:29:16 +02:00
Neil Jenkins
239b7d19e9 Ignore saved selection if not in document
The browser will rewrite the range if the nodes it refers to are removed from
the document, so check that it's still in the document before returning.
2017-07-07 11:48:42 +10:00
Neil Jenkins
0ae8322d04 Code tidying 2017-07-07 11:32:37 +10:00
Neil Jenkins
0b59a746f7 Ignore selectionchange events outside of editor
The selectionchange event handler can only be registered on the document
but we are not interested in changes of focus/selection that happen
outside of the editor, so check we have focus before firing the update
path event.
2017-07-07 11:32:18 +10:00
Neil Jenkins
a8f07d9adb Default to allowing URIs with unknown protocols 2017-06-28 16:03:31 +10:00
Neil Jenkins
601043f020 Fire a 'cursor' event so selection end can be monitored 2017-06-21 17:03:14 +10:00
Neil Jenkins
283a7d1d85 Don't consider editor focused if sub-element focused
Fixes #267
2017-05-10 14:22:56 +10:00
Neil Jenkins
632aae016b Code style fixup 2017-05-10 14:00:28 +10:00
kyuwoo.choi
9eacfb7b22 fix: handle insert table by CF_HTML
ms html clipboard format CF_HTML handles table like below if we copy part of table.
it makes problem when copying table from ms product such as ie, excel, powerpoint then pasting to squire.

<TABLE BORDER>
<!--StartFragment-->
<TR><TD>Item 6</TD><TD>Item 7</TD></TR><TR><TD>Item 10</TD><TD>Item 11</TD></TR>
<!--EndFragment-->
</TABLE>

and

<TABLE BORDER><TR>
<!--StartFragment-->
<TD>Item</TD>
<!--EndFragment-->
</TR></TABLE>

https://msdn.microsoft.com/en-us/library/windows/desktop/ms649015(v=vs.85).aspx
#274
2017-05-10 13:59:30 +10:00
Neil Jenkins
bb593e879a Don't insert <br> inside end of <a> on enter
Fixes #271
2017-03-21 17:06:44 +11:00
Neil Jenkins
70a2b48333 Return cached selection if not focused
If an action modifies the selection while the editor is not focused, we cannot
immediately set it in the DOM as this triggers focus. So instead we cache it and
restore on focus. If getSelection is called before the editor is next focused,
we need to return this new selection, not the current DOM selection.

Fixes #259
2017-02-11 09:40:56 -08:00
Neil Jenkins
45fee4c858 Fix potential infinite loop on cut
Common ancestor of range may change while range is manipulated for deletion.
2017-01-19 17:08:39 +11:00
Neil Jenkins
9596f4ecf8 Ensure moving boundaries up tree never passes root 2017-01-13 15:15:59 +11:00
Neil Jenkins
79ffc02557 Unify cut and copy implementations
* Data added to clipboard should now always be the same for cut as for copy
* Fixes bug when cutting across blocks, where not all parents would be included
  in the data added to the clipboard
2017-01-13 10:24:01 +11:00
Neil Jenkins
6f83f23881 Fix delete behaviour
1. Fixes cursor position when deleting starting with a selection at beginning
   of block.
2. Fixes block disappears when whole inline contents is deleted.
2017-01-10 10:06:28 +11:00
Neil Jenkins
066bdd2cde Ignore "cut" if no selection 2017-01-10 10:05:56 +11:00
Neil Jenkins
e645489f5f Fix empty lines missing when copying plain text 2017-01-10 10:05:35 +11:00
Neil Jenkins
e35ad32c09 Fix potential null deref when sanitizing html 2016-12-13 12:15:35 +11:00
Neil Jenkins
c1c63478f0 Check for queued events before disconnecting mutation observer
Fixes #252
2016-12-12 10:35:14 +11:00
Neil Jenkins
3d8cd62edb Improve copying of plain text on windows 2016-12-11 12:32:25 +11:00
Steven Allen
fcb8a4a63c
Use class constants 2016-12-08 21:03:50 -08:00
Neil Jenkins
2c7f7b907c Fix copying when not inside valid doc structure 2016-12-09 10:42:18 +11:00
Neil Jenkins
30dc11fd3c If deleting range to start/end of doc, collapse into a block 2016-12-09 10:41:52 +11:00
Steven Allen
9dcac8c94e Never pass null as root. 2016-12-08 13:11:52 -08:00
Neil Jenkins
65a621abcf null arg to setText(Alignment|Direction) should reset value
Resolves #247
2016-12-07 19:22:28 +11:00
Neil Jenkins
a899c001eb Fix null deref in insertHTML 2016-12-07 19:08:52 +11:00
Neil Jenkins
bb40d03899 Export useful Node helper functions 2016-12-07 18:42:48 +11:00
Neil Jenkins
504b40c857 Add pointer from root node to Squire instance.
Resolves #253
2016-12-07 17:54:13 +11:00
Neil Jenkins
9fac7ffdb6 Make HTML sanitization configurable.
And default to sanitizing setHTML content as well.
2016-12-07 17:24:16 +11:00
Neil Jenkins
801388222d Fix pasting plain text when not first item 2016-11-21 10:59:44 +11:00
Neil Jenkins
0b72f29ce5 Don't bother caching text node category 2016-11-21 10:59:11 +11:00
Neil Jenkins
f46dee1255 Memoize node category with weak map
Fix horrendous performance of isInline etc.
2016-11-15 11:07:15 +11:00
Neil Jenkins
8ab95e0dac Reset ignoreChange flag in modifyDocument method
Resolves #245
2016-11-04 11:17:31 +11:00