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

Maintain selection and composition during updateText() #115

Draft
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Draft
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
51 changes: 47 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,48 @@ <h3 id="editcontext-interface">EditContext Interface</h3>
</dl>
<ol>
<li>
Replace the substring of [=text=] in the range of |rangeStart| and |rangeEnd| with |newText|
<div class="note">It's permissible that |rangeStart| > |rangeEnd|. The substring between the indices should be replaced in the same way as when |rangeStart| <= |rangeEnd|.</div>
If |rangeStart| > |rangeEnd|, then swap the values of |rangeStart| and |rangeEnd|.
</li>
<li>
Replace the substring of [=text=] in the range of |rangeStart| and |rangeEnd| with |newText|.
</li>
<li>
If [=selection start=] is greater than |rangeEnd|, then set [=selection start=] to [=selection start=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
</li>
<li>
If [=selection start=] is greater than |rangeStart| and less than |rangeEnd|, then set [=selection start=] to |rangeStart| plus the length of |newText|.
</li>
<li>
If [=selection end=] is greater than |rangeEnd|, then set [=selection end=] to [=selection end=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
</li>
<li>
If [=selection end=] is greater than |rangeStart| and less than |rangeEnd|, then set [=selection end=] to |rangeStart| plus the length of |newText|.
</li>
<p class="note">
In other words, both selection boundary points are updated such that if they were after the affected range, they're offset by the overall change to the text length. If they were within the affected range, they're moved to the end of the new text.
If they were before the affected range, they're left unchanged.
</p>
<li>
If [=is composing=] is true, then:
<ol>
<li>
If min([=composition start=], [=composition end=]) is less than |rangeEnd| and max([=composition start=], [=composition end=]) is greater than |rangeStart|, then:
<ol>
<li>Set [=is composing=] to false.</li>
</ol>
</li>
<li>
Otherwise:
<ol>
<li>
If [=composition start=] is greater than |rangeEnd|, then set [=composition start=] to [=composition start=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
</li>
<li>
If [=composition end=] is greater than |rangeEnd|, then set [=composition end=] to [=composition end=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
</li>
</ol>
</li>
</ol>
</li>
</ol>
</div>
Expand All @@ -1079,10 +1119,13 @@ <h3 id="editcontext-interface">EditContext Interface</h3>
</dl>
<ol>
<li>
set [=selection start=] to |start|
If [=selection start=] is not equal to |start| or [=selection end=] is not equal to |end|, then set [=is composing=] to false.
</li>
<li>
Set [=selection start=] to |start|.
</li>
<li>
set [=selection end=] to |end|
Set [=selection end=] to |end|.
</li>
</ol>
</div>
Expand Down
Loading