-
Notifications
You must be signed in to change notification settings - Fork 40
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
Should the caret move by default, and should we define this behavior? #58
Comments
I think that "B" is mandatory. This is one of the messiest parts in cE right now and a quality spec is needed so the behavior is predictable. Also, a js implementation for it would be big, so passing this responsibility to the browser would be welcome, leaving js developers with the option to override the behavior when needed. It could go as part of "typing" (or by default whenever editing is enabled). The other options is making it an additional editing module, namely |
Putting it into another module certainly would be a clean division, I think. If it's really to be useful, it may end up being rather complex though, so it would probably be good if we could start. Also, it should be possible to override the behavior in the JS, so all the parts needed for that should be present (such as precise position info of caret, etc.). |
Hard to comment without knowing the diff between B and C. I think you're already aware of, but UAs might want some of inline movements such as related with RTL vary by platforms. So if you could start from "which platform differences are troubling editor developers" and try to spec them out, that'd be good, but I don't imagine we can define every details. Actually, doing so i18n-wise correctly is really really hard... |
@kojiishi Could you specify what parts of inline movement you want the UA to control? It is true that moving the caret is really hard, and that's editors either need full control or fully spec'ed movement or preferably both. Else one has to revert to tricks to get 4+ inconsistent browsers to do the same thing. |
In WebKit, there are many caret movement behaviors that are platform specific. While both Gecko and Trident/Edge tend to match Windows' caret behavior, WebKit tends to match OS X's. So I don't really think we can agree on single caret behavior since that would cause a significant UX regression for many of our users. Like I stated in another issue, the key here is to come up with a good abstraction to allow Web devs not to worry about platform-specific behaviors. If anything, they can cancel the default action and implement their own caret behavior. |
Yes, but this is kind of what contentEditable is trying today, right? And it's precisely because that is not working that we are at this point. The implementations have been fixed to work around the issues Gmail and some similar editors had in the past, but it doesn't work for all the editors made by non-browser-vendors, which all heavily override the default behavior.
Ok, if this is as far as you can go, then I think we should concentrate on making this work. It should be enough to allow to make custom editors. But for that we need some minimal information about actual current placement of caret, etc. . |
I don't buy the argument that the difference in selection behavior is what forced editors to override the default behavior. Gmail, for example, doesn't override selection/caret behavior as far as I can tell. What they override is undo/redo and other editing actions such as bolding of text. Anyway, we need to come up with a list of concrete use cases (e.g. building a collaborative editor) and associated requirements in order to talk about this. It's not really productive to talk about what we need to do without understanding what problem we're solving. |
As mentioned, Gmail was successful in getting contentEditable fixed in browsers so it would work for them. That's great for Gmail. The editor in Gmail is quite simple when it comes down to it. And the bug reports of the rest of us have been rejected for the last few years, often with the explanation that there is no specification so that there is nothing that tells us what is the correct or incorrect behavior. Then we were told that it cannot be fixed and that we need to get an entirely new alternative to contenteditable in which all behavior will be customizable by the JS code, and now we are being told that we won't get access to these primitives anyway. I don't think we are moving forward, and we kind of have presented bugs throughout the years in the form of bug reports. We mentioned some use cases in the other thread ( starting here: #56 (comment) ). We can go more into detail with those, or we can point to some of the bug reports that have been filed. |
It would be valuable to have a markdown document / wiki page listing all those issues or use cases so that we can use it to evaluate each new feature/API proposal. Otherwise, we may keep talking past each other like you're saying. |
@fredck @teleclimber @spocke: Do any of you have a list of everything that is wrong with contenteditable? @rniwa Did you see the explainer documents that Benjamin created [1]? It lists a number of use cases and explains why we have to go beyond contentEditable=True. |
Yes, I was the one who suggested have those lists of use cases and goals. But the fact contenteditable=true is broken doesn't mean that UAs need to have exactly one selection behavior and give up on platform friendless. Gecko, for example, allows users to change the way selection behaves in settings. OS X has a system-wide feature to enable split caret in bidirectional text. All these things need to be respected, and I don't see exposing each and every one of those configurations to editors as an option because developers are bound to get some combinations of them wrong. We really need to understand exactly what's broken with selection and address those issues instead. |
Have you tried to dig down into what current editors do? Basically they try to override everything, IME input/bidi/rtl is likely too complicated for many of those editors who only put 2-3 years of development time into an editor. So I doubt that there is much "common feel" in place today that you can break. Just take what we are typing in here on Github: I am using Chrome, and I notice that overtype is disabled although it is enabled everywhere else. If I right-click and choose
We have mentioned several use cases. The way forward, as I can see it, is to follow the Extensible Web Manifesto [1]: Gives us (the web developers) the necessary primitives to implement things ourselves in JavaScript. Once that has been done, and you can tell that there are some common operations that everyone does in the same way and that could gain something from being moved to the browser, then you can add specs with higher layer features on top of the lower layer spec you initially made. I think it would be helpful to find out if we are going to get any compromise on this part from the part of browser makers, or if browsers are going to continue to try to manage editing down to the smallest detail and make it hard for JS to define or even override anything. If that is the case, then I cannot see how we are going to get any further with this spec then with what already exists. |
I don't think we should add any API without understanding use cases. We need to understand each and every use case for which existing editors are overriding browser default behavior and come up with a solution instead of providing bunch of platform dependent "primitives" and hope for the best. |
@rniwa: We have listed use cases both here, and as I pointed you to, Benjamin made an extensive document about just that. It sounds to me as if you are thinking about fixing contentEditable=True. If it is possible to do that without breaking legacy sites, I am all for that. We have all provided a long list of bug reports to all the browsers over the years and we can point to all those again. The people you have been discussing with here (me excluded) have been building JS based editors for many many years and are probably some of the world's most dedicated experts when it comes to contentEditable=True, so it's not like they don't know what they are talking about. Fixing contentEditable=True is a great idea. contentEditable=Typing is about something else. It is about providing primitives and to give control that used to be in the browser over to JavaScirpt. I understand your statement as meaning that you are against cE=Typing in principle. That is noted, but then I think it would probably be better if you concentrated your efforts on fixing contentEditable=True. |
You're extrapolating too much. I'm only concerned about real problems. I'm against any API unless it solves some problem is all I'm saying, and the list of problems each API solves needs to be explicitly documented. It's not enough to say "beacuse that's a primitive necessary to build an editor". That's not a use case, and not any evidence to suggest the proposed API is necessary or the most appropriate form of the solution. "Giving control to JavaScript" sounds cool and sexy but that doesn't solve any real problem on its own. |
@rniwa: The idea with the Extensible Web Manifesto is that you start out by giving us JS developers the primitives needed to implement feature X entirely in JS. Then, as the next step, you the work together with JS developers to create higher level specs based on JS polyfills. Did I misunderstand you on any of that? Are there any new primitives you would be willing to offer? Such as exact information about where the caret(s) currently are? And a way to set them? |
That's not all what I'm saying at all. I'm here to participate in the discussion to come up with a new editing API that WORKS. It doesn't matter whether it "provides primitive" or "gives more power to JS". Letting JavaScript see exactly where the caret is placed doesn't solve any problem on its own and IMO introduces more problems for bidi users because caret will show up at two different locations at boundaries of bidi levels. Gecko, for exmaple, changes the location at which caret appears depending from which direction you moved the caret. I don't think Web apps want to have a bunch of if-else statements to check the preferences of Gecko and behave differently based on that. The fact selection behaves differently in different browsers is not necessary a bug. Some of the behavioral differences are intential and features. So that's why I'm asking for you to list the problems you have with the current selection APIs and behaviors so that we can come up with the right set of APIs and spec's that address those issues without degrading user experience in CJK languages, bidirectional text, and platform-specific behaviors. The reason editing API hasn't improved over the last decade or two isn't because we've been lazy. It's because HTML editing is really hard. We can't just add a bunch of half-baked "primitives" and magically solve the problem. If anything, that'll only exacerbate the problem we have today. |
That's fine, but that's not what contentEditable=Typing set out to do. It's only about offering primitives to JS libraries to create editors. It is not about providing an editor to end users that works.
I think that would be the least of our worries. For example, the standard package CKEditor is 2.9 MB, so a few if-else statements more would certainly not break any camel's back. And hopefully the 2.9 MB could be slimmed down quite a bit as well.
If we could, many of us would simply override such behavior. And it's a bit weird: Noone tries to tell us what size or shape pull down menus are to be or that menu buttons only go on the right and that the background of all webpages is light blue when seen in Safari to preserve a common experience when surfing the web using Safari. Yet when it comes to editing, somehow it is felt that this needs to be centrally managed.
Ok, so you want a list of the most important contentEdtiable bug reports? If there is a chance they will be fixed, I am certain we will be able to provide those to you very quickly. (Btw, this is mainly NOT about the selection API, but about contenteditable. Some things may end up being discovered as also be issues for the selection API, but in general that's not what the discussion is about here).
Noone is accusing you of being lazy. My understanding of the situation was that the browser makers accepted that they will not ever be able to solve this problem and that therefore they will instead hand the task of creating editors over to the JS groups/projects/companies that dedicate themselves to creating editors. That's why I am somewhat confused that you seem to want to go the other direction again and not give us the primitives and instead create a new form of contewntEditable=True.
Can you explain why you think the problem will grow bigger if the editing logic is being moved to the JS? The primitives we are asking for are not just random things. They are all backed up with use cases and are suggested by people with many years of experience in this field. As for bugs: they have also been filed many years ago. Otherwise, I don't think we get any further here. I suggest you start a new spec with the working editing api that does not offer primitives but "really works". The editing task force already hosts various specs, of which we are still not entirely certain which one survives, so adding one more shouldn't be a problem. I would then also suggest you look through our use cases and bug reports and come up with some concrete suggestions on how to handle things. |
I beg your pardon? I was right there when we initially came up with the idea of Goals (https://w3c.github.io/editing/editing-explainer.html#goals):
|
Also in general, Web Apps WG and HTML WG design APIs to address concrete use cases. We don't just spec API because it exposes new primitives to JS. I understand your frustration but you really need to give us a list of concrete use cases that necessiates each API/feature instead of saying that you know it better. |
Yes, those two goals is what at least I understand as "exposing primitives to JS". But lets just agree to disagree on this.
Ok, what was not good enough about the use cases that were already listed? Also note that I never claimed that I knew anything better. What primitives you are exposing is totally up to you. You are the browser expert, not me. We just need something. |
Going back to the original topic of this issue, which is about how the default selection behavior should be defined, we need to understand selection behavior requirements for each use case below, and understand why the current selection API is inadaquate:
For example, for 3, I'd imagine that selection cannot cross editability boundary so we need to spec how UA "fixes" selection when the selection is set across different editability. Or maybe we need to allow it. Or perhaps it needs to be configurable. For 4, perhaps code highlighting happens asynchronusly so we need to provide a mechanism by which apps can replace the underlying DOM while preserving the selection set by the user. And so forth. Once we've listed all those requirements, we can then begin to think of a solution that address them. |
I think that's another topic (but also an important one!). "caret movement" was meant as "Where does the caret go when I hit the right/left/up/down arrow keys". As far as I can tell, the selection API says nothing about any of that. But there may be some connection: I haven't investigated it, but I guess it's possible that the reason the caret currently isn't going into certain places currently when moving around with the arrow keys is that it is prevented from creating a selection in certain places. |
The problem is that caret behavior is platform dependent just as much as focusing behavior is (see section 6 of HTML spec) and we can't really agree on single behavior across platforms and browsers. We need to understand the underlying motivation / use case and come up with an alternative approach instead. |
@rniwa OK, so your short answer is option D, correct? |
Perhaps but we might be able to do C depending on what needs to be spec'ed. e.g. legal positions for selection end points. |
D is a clear answer. Now you wonder why one would want to use standardized caret behavior in the various examples you mention there. As for the examples you mention:
I don't think any of those really can or should be done in contenteditable directly, even if it's 100% fixed. The amount of possible errors is just way too high. Instead it needs to be implemented as a datastructure that is managed by some Javascript code that renders it in the DOM and records any changes made to it by the user as atomic commits which can then be stored, rolled back, shared with others in a collaborative environment, etc.. This is probably also true for other complex editors, especially when combining several complex sub components. |
Thanks for the clarification but what I'm asking why and how do the differences in selection behaviors among browsers are causing problems in those editors. You've mentioned that you've filed many bugs in the past but what are those bugs? And which feature / user scenario end up encountering those bugs? |
I think the track changes one is a good example: I don't think anyone knows why it worked about a year ago and what exactly make it stop. The way to create it was simply: Create some basic code and some basic tests. Add if clauses to the code until the tests all work. Then try it out in real-life. Whenever you run into another issue, create another test and add another if clause somewhere in the code until it works. Then you test on other browsers and add more if clauses, and so on. Every time a new Firefox or Chrome version comes out, run all the tests. If something is broken, add more if clauses in the code until all the tests run again, etc. . So it's just one gigantic mess of spaghetti code. What you can do is try to remove some of the if statements and then see what happens and what breaks in what browser. This track changes plugin can now be found in derived versions as plugins for the main contenteditable-based editors. And I think it's the only one so far. As for some bug reports: Your issue nr 3 (non-editable islands): https://code.google.com/p/chromium/issues/detail?id=238000#c6 Most relevant for caret movement is this one: https://bugzilla.mozilla.org/show_bug.cgi?id=873883 (also reported to Chrome and also contacted Webkit team at the time they still were united). The caret cannot move between these elements. It can move between some in Firefox and others in Chrome. Just moving around images is working in both. These are important because using canvases, within a line is a way to make sure that footnotes are placed correctly and can be moved with copy and pasting -- I created a demo with that here: http://johanneswilm.github.io/canvasContentEditable/ . |
Oh those seems like real bugs that need to be fixed in each browser, and that's something we can definitely spec (how caret behaves around non-editable content). |
OK. I will give some use-cases in which the default caret movement behaviour (today) is not suitable:
I don't want any caret position inside the two
When the caret is in the
There should be no caret between the span elements, text entered there does not have any meaning.
There should be no caret inside the
When the user moves the caret up, the Some personal remarks:
|
I agree that this still does not create a full editor for us. The situation now however seems to be the following:
The above, I would assume, covers about 99.9% of small to medium sized sites. Every fortnight there is someone saying he has created the perfect replacement for the above-mentioned editors that is able with just 2kb of code to replace the above editors. The way that goes is usually: they work enough to type a few words in an editor for demo purposes, but if one actually tries to write a text with them, one quickly runs into the numerous contenteditable bugs that they have not been able to cover with their 2kb code. So they start adding more code to it as they find out that their editor doesn't work. This can take some 2-3 years. AT that stage it's as complex as the above mentioned editors, or development has ceased before they ever got there. I can see two other types of contenteditable-based editors:
I would assume that you fall into one of these last two categories. The idea is to shift the creation of these libraries from browsers, who have a million other things to do and don't really have time and resources to put into constantly thinking about editing, to JS developers working on editors who do nothing else than concern themselves with editing. If the primitives actually get implemented, I expect there to grow maybe 1,2,3 different libraries that can take care of most of the editing. They shouldn't be as large and bulky as what is needed in the editors right now, because they can rely that the browsers behave the same way and don't constantly change. Also, the rest of us can commit JS patches much easier than patches to browsers. It is my understanding that the Chrome team even for a while had planned to move execCommand to Blink-in-JS internally for that precise reason. The structure would then be:
With time, the functions the Middle layer performs may be moved into the browser itself after having been spec'ed thoroughly. |
@johanneswilm If you talk about contenteditable=true in general, I totally agree with what you said. I was talking about selection in particular and I was just sceptical that a JS library will be able to reimplement the exact same selection behaviour that is today in browsers (and which works great for the end-users) and offer an API such that it can be easily integrated in an editor. @rniwa Are the use-cases above what you were looking for? |
@ctalau: I think we need to make a distinction between selection as meaning "the user highlights something" and "the user moves the caret"/"the user inserts something at the caret position". They may both have selection at their base, but I have a feeling their are handled quite differently by editors:
|
PS: Another difficulty with browsers that insert content and have restrictions on where carets can go in even slightly different ways is trying to synchronize them.
|
I was talking about caret movement without necesarily inserting something right away. In the examples I gave, I simply would not want it to blink there.
Does there exist an open-source implementation that moves the caret in block-direction in an arbitrarly styled HTML content? |
@ctalau: Yes
[1] http://www.alohaeditor.org/demo/aloha-ui/ Btw -- in the cheapscape implementation I "only" spent about a year on programming for Fidus Writer, we let the browser handle the movement and only when it's done, we adjust the caret placement to go where it really "should" be. This approach seemed useful for a long time, but I have realized quite a while ago that this is unsolvable. Possibly it could be made to work by constantly having a 3-4 developer team monitor the state of all browsers and always fix everything when something changes, but that's just resources we don't have. Which is why we need to switch... to one of the already existing editors for that part. The problem with that is that none of them are able to do all the things we need (track changes, collaborative editing, non-editable islands, mathjax, comments, etc.). |
@ctalau : the problems you've listed are extremely useful. It looks like me that the bulk of issues can be resolved if we introduced new values for Saving/restoring selection state is covered in w3c/selection-api#42. |
@rniwa The non-editable contents is just one example in that bug report [1]. Other issues are movement around inline SVGs, inline canvas elements and inline non-editable elements with editable islands. Where do you think such a specification should go? |
Definitely, selection API. That's the spec for defining the selection behavior in general. |
@rniwa: Ok, so will you add it there? Will fixing this not break anything that exists so far? |
Well, that's up to the WebApps working group, the author of the specification. I'm just an editor; my job is to document the consensus of the working group. I can't decide what goes into the spec. Of course, I haven't updated the spec in a while since I've been busy with other stuff but I'm intending to get back to it in a couple of months (hopefully before F2F in Warsar). |
@rniwa Sure the WG can can overrule a proposal from you to add this. But you agree that this should be specified, right? The same way you added an issue for w3c/selection-api#46 , could we also add an issue for this? I hadn't looked at the issue list of the selection API and I now notice that I added a number of things with examples there about half a year ago. Some of the things mentioned in issues there are the same things we have been mentioning here. |
Yes, I agree. This should be spec'ed in selection API spec. Since I'm not too familiar with what kind of issues exist with inline SVG, etc... it would be best if you could file new issues. |
@rniwa, @johanneswilm, the whole discussion has been maybe way too noisy, unnecessarily. The root of the problem is that currently browsers don't have any specification to follow and so each one defines its own rules when implementing caret behavior. Therefore spec'ing it makes sense, even if good part of the documentation will state that "it should mimic the platform behavior". Note that we're much probably not talking about the API specs (which ofc will be included) but about spec'ing the default expected behavior of UAs... default behavior hopefully built on top of the API, so it can be fully overriden by js. |
@rniwa @fredck If I understand @rniwa correctly, everything that has to do with caret movement has been transferred to the selection API, which means that caret movement in contenteditable=Typing and and ce=true will be the same. I am totally OK with having predefined behavior that is platform dependent, as long as we have ways to override that. The most difficult thing in that respect that I know of has been moving the caret in the block direction. Now that it seems like we will get information about the caret placement (start or end of the line: w3c/selection-api#32 ), this should no longer be a problem. |
Options mentioned so far:
A) Don't move the caret by default and don't define default behavior.
B) Move the caret by default and define the default behavior in a spec.
C) Move the caret by default and define some of the default behavior and leave the rest to be decided by UA/platform (for example: let UA decide on line block direction movement, but define inline movement in spec).
D) Move the caret by default, but do not spec this behavior. Instead, let the UA/platform decide what that behavior will look like.
This is the default inline movement we initially had in the spec before it was removed:
The text was updated successfully, but these errors were encountered: