forked from forgejo/forgejo
Support pasting URLs over markdown text (#29566)
Support pasting URLs over selection text in the textarea editor. Does
not work in EasyMDE and I don't intend to support it. Image paste works
as usual in both Textarea and EasyMDE.
The new `replaceTextareaSelection` function changes textarea content via
[`insertText`](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand#using_inserttext)
command, which preserves history, e.g. `CTRL-Z` works and is also
demostrated below. We should later refactor the image paste code to use
the same function because it currently destroys history.
Overriding the formatting via `Shift` key is supported as well, e.g.
`Ctrl+Shift+V` will insert the URL as-is, like on GitHub.

(cherry picked from commit a3cfe6f39ba33cea305de592a006727857014c53)
This commit is contained in:
parent
18e0647c84
commit
4511287676
5 changed files with 103 additions and 31 deletions
|
@ -1,6 +1,13 @@
|
|||
import {pathEscapeSegments} from './url.js';
|
||||
import {pathEscapeSegments, isUrl} from './url.js';
|
||||
|
||||
test('pathEscapeSegments', () => {
|
||||
expect(pathEscapeSegments('a/b/c')).toEqual('a/b/c');
|
||||
expect(pathEscapeSegments('a/b/ c')).toEqual('a/b/%20c');
|
||||
});
|
||||
|
||||
test('isUrl', () => {
|
||||
expect(isUrl('https://example.com')).toEqual(true);
|
||||
expect(isUrl('https://example.com/')).toEqual(true);
|
||||
expect(isUrl('https://example.com/index.html')).toEqual(true);
|
||||
expect(isUrl('/index.html')).toEqual(false);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue