summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2011-10-27 23:36:12 +0000
committercorvid <corvid@lavabit.com>2011-10-27 23:36:12 +0000
commit64ffdf72ac7bc4101e3b794bb7469180aed14cb9 (patch)
tree0f9b12ed47dcd80aefec3d72841588548ace34f3
parent42dedf95155ac83091d426bdd1813937bac5655f (diff)
improve combining char handling in text selection
It's not conceptually difficult, and yet the code did not want to become nice and clean.
-rw-r--r--dw/textblock.cc28
1 files changed, 22 insertions, 6 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 02769e23..4de41c67 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -666,18 +666,34 @@ bool Textblock::sendSelectionEvent (core::SelectionState::EventType eventType,
link = word->style->x_link;
}
if (word->content.type == core::Content::TEXT) {
- for (int glyphWidth, glyphX = wordStartX;
- event->xWidget > glyphX;
- glyphX += glyphWidth) {
+ int glyphX = wordStartX;
+
+ while (1) {
int nextCharPos =
layout->nextGlyph (word->content.text, charPos);
- glyphWidth =
+ int glyphWidth =
textWidth (word->content.text, charPos,
nextCharPos - charPos, word->style);
- if (event->xWidget >= glyphX + glyphWidth/2) {
- // include it unless we're on the left half
+ if (event->xWidget > glyphX + glyphWidth) {
+ glyphX += glyphWidth;
+ charPos = nextCharPos;
+ continue;
+ } else if (event->xWidget >= glyphX + glyphWidth/2){
+ // On the right half of a character;
+ // now just look for combining chars
charPos = nextCharPos;
+ while (word->content.text[charPos]) {
+ nextCharPos =
+ layout->nextGlyph (word->content.text,
+ charPos);
+ if (textWidth (word->content.text, charPos,
+ nextCharPos - charPos,
+ word->style))
+ break;
+ charPos = nextCharPos;
+ }
}
+ break;
}
} else {
// Depends on whether the pointer is within the left or