Skip to content

Commit

Permalink
Merge pull request #5 from JetBrains/fix-ligatures-cursor
Browse files Browse the repository at this point in the history
Fix cursor position in ligatures
  • Loading branch information
olonho authored Mar 11, 2022
2 parents 90dbf97 + b2e0876 commit f87c5b5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
default: 'false'

env:
version: m99-f85ab491eb
version: m99-f85ab491eb-2

jobs:
macos:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Update `version` in [.github/workflows/build.yml](https://github.com/JetBrains/s
## Building locally

```sh
python3 script/checkout.py --version m99-f85ab491eb
python3 script/checkout.py --version m99-f85ab491eb-2
python3 script/build.py
python3 script/archive.py
```

To build a debug build:

```sh
python3 script/checkout.py --version m99-f85ab491eb
python3 script/checkout.py --version m99-f85ab491eb-2
python3 script/build.py --build-type Debug
python3 script/archive.py --build-type Debug
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Index: modules/skparagraph/src/TextLine.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/modules/skparagraph/src/TextLine.cpp b/modules/skparagraph/src/TextLine.cpp
--- a/modules/skparagraph/src/TextLine.cpp (revision f85ab491eb97b54d0bfeac19fed27feb499b8912)
+++ b/modules/skparagraph/src/TextLine.cpp (date 1646928189139)
@@ -615,6 +615,7 @@
}
return result;
}
+ TextRange origTextRange = textRange;
// Find [start:end] clusters for the text
Cluster* start = nullptr;
Cluster* end = nullptr;
@@ -688,8 +689,8 @@
// TODO: This is where we get smart about selecting a part of a cluster
// by shaping each grapheme separately and then use the result sizes
// to calculate the proportions
- auto leftCorrection = start->sizeToChar(textRange.start);
- auto rightCorrection = end->sizeFromChar(textRange.end - 1);
+ auto leftCorrection = start->sizeToChar(origTextRange.start);
+ auto rightCorrection = end->sizeFromChar(origTextRange.end - 1);
result.clip.fLeft += leftCorrection;
result.clip.fRight -= rightCorrection;
result.clippingNeeded = leftCorrection != 0 || rightCorrection != 0;
@@ -1248,6 +1249,27 @@
auto clusterIndex8 = context.run->globalClusterIndex(found);
auto clusterEnd8 = context.run->globalClusterIndex(found + 1);

+ size_t charsInCluster = 0;
+ for (auto i = clusterIndex8; i < clusterEnd8; i++) {
+ i = run->owner()->findNextGraphemeBoundary(i);
+ if (i < clusterEnd8) charsInCluster++;
+ }
+
+ // Calculate offset for a character inside a ligature (e.g. ff or ffi)
+ // Considering all characters in the ligature have equal width
+ if (glyphemePosWidth > 0 && charsInCluster > 1) {
+ glyphemePosWidth /= charsInCluster;
+ size_t charIndexInCluster = std::floor((dx - glyphemePosLeft) / glyphemePosWidth);
+ if (!context.run->leftToRight()) {
+ charIndexInCluster = charsInCluster - charIndexInCluster;
+ }
+ glyphemePosLeft += charIndexInCluster * glyphemePosWidth;
+ for (size_t i = 0; i < charIndexInCluster; i++) {
+ clusterIndex8 = run->owner()->findNextGraphemeBoundary(clusterIndex8 + 1);
+ }
+ clusterEnd8 = run->owner()->findNextGraphemeBoundary(clusterIndex8 + 1);
+ }
+
SkScalar center = glyphemePosLeft + glyphemePosWidth / 2;
if ((dx < center) == context.run->leftToRight()) {
size_t utf16Index = context.run->leftToRight()
4 changes: 2 additions & 2 deletions script/update_version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/..
OLDVER=m99-51988d0bc1
NEWVER=m99-f85ab491eb
OLDVER=m99-f85ab491eb
NEWVER=m99-f85ab491eb-2
find -E $ROOT/script *.md .github -regex '.*\.(py|md|yml)' -exec sed -i '' -e "s/$OLDVER/$NEWVER/g" {} \;

0 comments on commit f87c5b5

Please sign in to comment.