Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: improve selection experience #1264

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/suneditor.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,10 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
_w.setTimeout(function () {
if (typeof plugin.select === 'function') this.callPlugin(pluginName, plugin.select.bind(this, element), null);
this._setComponentLineBreaker(element);

const compContext = context[pluginName];
const container = compContext._container;
core.setRange(container, 0, container, 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is a problem when entering text after selecting an image.
After the merge, this code will be removed.
Thank you for your contribution.!

Copy link
Contributor Author

@SystemChanger SystemChanger Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is crucial for my other PRs and is important for overall logic of selection - only one acceptable target at once (text, component or selection range). Such logic has a positive effect on many things - from removing flashing carriage on text to preventing overlapping handlers from different selection targets.
Are you talking about pressing text keys when there is a selected component? (that leads to text insertion to component figure area)
If I get you right, this problem was already there. (but may have different steps to reproduce the problem, e.g. pressing left/right arrow keys to position on component figure from the text node at first).
This code just makes this problem more explicit, and I also get rid of it in the further PRs.
Does it get fixed with next PR: https://github.com/JiHong88/suneditor/pull/1267/commits ?
I've done some enhancements and fixes in PRs, that altered the current behavior of keyboard interaction with components (images, videos) and explicit setting range to component area is really important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend including this code. Just a friendly reminder so you don't forget it when the time to work with PRs will come. @JiHong88

}.bind(this));
},

Expand Down Expand Up @@ -4517,6 +4521,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
break;
case 'selectAll':
this.containerOff();
this.controllersOff();
const wysiwyg = context.element.wysiwyg;
let first = util.getChildElement(wysiwyg.firstChild, function (current) { return current.childNodes.length === 0 || current.nodeType === 3; }, false) || wysiwyg.firstChild;
let last = util.getChildElement(wysiwyg.lastChild, function (current) { return current.childNodes.length === 0 || current.nodeType === 3; }, true) || wysiwyg.lastChild;
Expand Down Expand Up @@ -6812,6 +6817,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
},

onInput_wysiwyg: function (e) {
if (!document.body.contains(core.currentControllerTarget)) core.controllersOff();

if (core.isReadOnly || core.isDisabled) {
e.preventDefault();
e.stopPropagation();
Expand Down