diff dwt/custom/DefaultContent.d @ 274:62a03a4c21c8

sync StyledText with dwt-linux
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 23:40:57 +0200
parents a63e2cd5485e
children
line wrap: on
line diff
--- a/dwt/custom/DefaultContent.d	Sun Aug 03 02:21:43 2008 +0200
+++ b/dwt/custom/DefaultContent.d	Sun Aug 03 23:40:57 2008 +0200
@@ -21,10 +21,10 @@
 import dwt.custom.StyledTextEvent;
 import dwt.custom.StyledTextListener;
 import dwt.custom.StyledText;
+import dwt.dwthelper.utils;
 
 static import tango.io.model.IFile;
 static import tango.text.Text;
-import dwt.dwthelper.utils;
 
 alias tango.text.Text.Text!(char) StringBuffer;
 
@@ -32,7 +32,7 @@
     private final static String LineDelimiter = tango.io.model.IFile.FileConst.NewlineString;
 
     StyledTextListener[] textListeners; // stores text listeners for event sending
-    String textStore; // stores the actual text
+    char[] textStore; // stores the actual text
     int gapStart = -1;  // the character position start of the gap
     int gapEnd = -1;    // the character position after the end of the gap
     int gapLine = -1;   // the line on which the gap exists, the gap will always be associated with one line
@@ -734,7 +734,7 @@
  * <p>
  *
  * @param listener the listener which should no longer be notified
- * 
+ *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT when listener is null</li>
  * </ul>
@@ -891,4 +891,33 @@
     lineCount_ -= numOldLines;
     gapLine = getLineAtPhysicalOffset(gapStart);
 }
+
+/++
+ + DWT extension
+ +/
+int utf8AdjustOffset( int offset ){
+    if (textStore is null)
+        return offset;
+    if (offset is 0)
+        return offset;
+    if( offset >= textStore.length ){
+        return offset;
+    }
+    if (!gapExists() || (offset < gapStart)){
+        while( textStore[offset] & 0xC0 is 0x80 ){
+            offset--;
+        }
+        return offset;
+    }
+    int gapLength= gapEnd - gapStart;
+    if( offset+gapLength >= textStore.length ){
+        return offset;
+    }
+    while( textStore[offset+gapLength] & 0xC0 is 0x80 ){
+        offset--;
+    }
+    return offset;
 }
+
+
+}