From 7c91570b948b88e3bc6cc6a84d894cd5fbf647e5 Mon Sep 17 00:00:00 2001 From: Dan Clark Date: Thu, 13 Mar 2025 00:07:06 +0000 Subject: [PATCH 1/3] Update selection during updateText() --- index.html | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index cce9947..cc5c741 100644 --- a/index.html +++ b/index.html @@ -1058,9 +1058,27 @@

EditContext Interface

  1. - Replace the substring of [=text=] in the range of |rangeStart| and |rangeEnd| with |newText| -
    It's permissible that |rangeStart| > |rangeEnd|. The substring between the indices should be replaced in the same way as when |rangeStart| <= |rangeEnd|.
    + If |rangeStart| > |rangeEnd|, then swap the values of |rangeStart| and |rangeEnd|.
  2. +
  3. + Replace the substring of [=text=] in the range of |rangeStart| and |rangeEnd| with |newText|. +
  4. +
  5. + If [=selection start=] is greater than |rangeEnd|, then set [=selection start=] to [=selection start=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|). +
  6. +
  7. + If [=selection start=] is less greater than |rangeStart| and less than |rangeEnd|, then set [=selection start=] to |rangeStart| plus the length of |newText|. +
  8. +
  9. + If [=selection end=] is greater than |rangeEnd|, then set [=selection end=] to [=selection end=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|). +
  10. +
  11. + If [=selection end=] is less greater than |rangeStart| and less than |rangeEnd|, then set [=selection end=] to |rangeStart| plus the length of |newText|. +
  12. +

    + 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. +

From 97353945b972e3f4d428203e5f340505d92c195d Mon Sep 17 00:00:00 2001 From: Dan Clark Date: Thu, 13 Mar 2025 00:14:38 +0000 Subject: [PATCH 2/3] Update composition during updateText() --- index.html | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index cc5c741..9105145 100644 --- a/index.html +++ b/index.html @@ -1067,18 +1067,40 @@

EditContext Interface

If [=selection start=] is greater than |rangeEnd|, then set [=selection start=] to [=selection start=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
  • - If [=selection start=] is less greater than |rangeStart| and less than |rangeEnd|, then set [=selection start=] to |rangeStart| plus the length of |newText|. + If [=selection start=] is greater than |rangeStart| and less than |rangeEnd|, then set [=selection start=] to |rangeStart| plus the length of |newText|.
  • If [=selection end=] is greater than |rangeEnd|, then set [=selection end=] to [=selection end=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|).
  • - If [=selection end=] is less greater than |rangeStart| and less than |rangeEnd|, then set [=selection end=] to |rangeStart| plus the length of |newText|. + If [=selection end=] is greater than |rangeStart| and less than |rangeEnd|, then set [=selection end=] to |rangeStart| plus the length of |newText|.
  • 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.

    +
  • + If [=is composing=] is true, then: +
      +
    1. + If min([=composition start=], [=composition end=]) is less than |rangeEnd| and max([=composition start=], [=composition end=]) is greater than |rangeStart|, then: +
        +
      1. Set [=is composing=] to false.
      2. +
      +
    2. +
    3. + Otherwise: +
        +
      1. + If [=composition start=] is greater than |rangeEnd|, then set [=composition start=] to [=composition start=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|). +
      2. +
      3. + If [=composition end=] is greater than |rangeEnd|, then set [=composition end=] to [=composition end=] plus the length of |newText| minus (|rangeEnd| minus |rangeStart|). +
      4. +
      +
    4. +
    +
  • From 87e9721c9f475ae08b04bee640ea76b9b28f0160 Mon Sep 17 00:00:00 2001 From: Dan Clark Date: Thu, 13 Mar 2025 00:42:45 +0000 Subject: [PATCH 3/3] Terminate composition if updateSelection() changes selection --- index.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 9105145..140f242 100644 --- a/index.html +++ b/index.html @@ -1119,10 +1119,13 @@

    EditContext Interface

    1. - 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.
    2. - set [=selection end=] to |end| + Set [=selection start=] to |start|. +
    3. +
    4. + Set [=selection end=] to |end|.