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

461 commits

Author SHA1 Message Date
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
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