comparison dwt/custom/StyledText.d @ 275:9c5ba1f00519

Fix: delete the whole codepoint for backspace. Fix: getPointAtPosition handle whole codepoints correctly.
author Frank Benoit <benoit@tionex.de>
date Tue, 05 Aug 2008 00:51:33 +0200
parents 62a03a4c21c8
children
comparison
equal deleted inserted replaced
274:62a03a4c21c8 275:9c5ba1f00519
2238 sendKeyEvent(event); 2238 sendKeyEvent(event);
2239 } else if (caretOffset > 0) { 2239 } else if (caretOffset > 0) {
2240 int lineIndex = content.getLineAtOffset(caretOffset); 2240 int lineIndex = content.getLineAtOffset(caretOffset);
2241 int lineOffset = content.getOffsetAtLine(lineIndex); 2241 int lineOffset = content.getOffsetAtLine(lineIndex);
2242 if (caretOffset is lineOffset) { 2242 if (caretOffset is lineOffset) {
2243 // DWT: on line start, delete line break
2243 lineOffset = content.getOffsetAtLine(lineIndex - 1); 2244 lineOffset = content.getOffsetAtLine(lineIndex - 1);
2244 event.start = lineOffset + content.getLine(lineIndex - 1).length; 2245 event.start = lineOffset + content.getLine(lineIndex - 1).length;
2245 event.end = caretOffset; 2246 event.end = caretOffset;
2246 } else { 2247 } else {
2247 TextLayout layout = renderer.getTextLayout(lineIndex); 2248 TextLayout layout = renderer.getTextLayout(lineIndex);
2248 int start = layout.getPreviousOffset(caretOffset - lineOffset, DWT.MOVEMENT_CHAR); 2249 int start = layout.getPreviousOffset(caretOffset - lineOffset, DWT.MOVEMENT_CLUSTER);
2249 renderer.disposeTextLayout(layout); 2250 renderer.disposeTextLayout(layout);
2250 event.start = start + lineOffset; 2251 event.start = start + lineOffset;
2251 event.end = caretOffset; 2252 event.end = caretOffset;
2252 } 2253 }
2253 sendKeyEvent(event); 2254 sendKeyEvent(event);
3985 * relative to the beginning of the document 3986 * relative to the beginning of the document
3986 */ 3987 */
3987 int getOffsetAtPoint(int x, int y, int lineIndex) { 3988 int getOffsetAtPoint(int x, int y, int lineIndex) {
3988 TextLayout layout = renderer.getTextLayout(lineIndex); 3989 TextLayout layout = renderer.getTextLayout(lineIndex);
3989 x += horizontalScrollOffset - leftMargin; 3990 x += horizontalScrollOffset - leftMargin;
3990 int[] trailing = new int[1]; 3991 int[1] trailing;
3991 int offsetInLine = layout.getOffset(x, y, trailing); 3992 int offsetInLine = layout.getOffset(x, y, trailing);
3992 caretAlignment = OFFSET_LEADING; 3993 caretAlignment = OFFSET_LEADING;
3993 if (trailing[0] !is 0) { 3994 if (trailing[0] !is 0) {
3994 int lineInParagraph = layout.getLineIndex(offsetInLine + trailing[0]); 3995 int lineInParagraph = layout.getLineIndex(offsetInLine + trailing[0]);
3995 int lineStart = layout.getLineOffsets()[lineInParagraph]; 3996 int lineStart = layout.getLineOffsets()[lineInParagraph];
4907 } 4908 }
4908 Point point; 4909 Point point;
4909 TextLayout layout = renderer.getTextLayout(lineIndex); 4910 TextLayout layout = renderer.getTextLayout(lineIndex);
4910 if (lineLength !is 0 && offsetInLine <= lineLength) { 4911 if (lineLength !is 0 && offsetInLine <= lineLength) {
4911 if (offsetInLine is lineLength) { 4912 if (offsetInLine is lineLength) {
4912 point = layout.getLocation(offsetInLine - 1, true); 4913 // DWT: Instead of go back one byte, go back one codepoint
4914 int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER);
4915 point = layout.getLocation(offsetInLine_m1, true);
4913 } else { 4916 } else {
4914 switch (caretAlignment) { 4917 switch (caretAlignment) {
4915 case OFFSET_LEADING: 4918 case OFFSET_LEADING:
4916 point = layout.getLocation(offsetInLine, false); 4919 point = layout.getLocation(offsetInLine, false);
4917 break; 4920 break;
4918 case PREVIOUS_OFFSET_TRAILING: 4921 case PREVIOUS_OFFSET_TRAILING:
4919 default: 4922 default:
4920 if (offsetInLine is 0) { 4923 if (offsetInLine is 0) {
4921 point = layout.getLocation(offsetInLine, false); 4924 point = layout.getLocation(offsetInLine, false);
4922 } else { 4925 } else {
4923 point = layout.getLocation(offsetInLine - 1, true); 4926 // DWT: Instead of go back one byte, go back one codepoint
4927 int offsetInLine_m1 = layout.getPreviousOffset(offsetInLine, DWT.MOVEMENT_CLUSTER);
4928 point = layout.getLocation(offsetInLine_m1, true);
4924 } 4929 }
4925 break; 4930 break;
4926 } 4931 }
4927 } 4932 }
4928 } else { 4933 } else {
8321 } 8326 }
8322 setScrollBars(true); 8327 setScrollBars(true);
8323 setCaretLocation(); 8328 setCaretLocation();
8324 super.redraw(); 8329 super.redraw();
8325 } 8330 }
8331 // DWT: If necessary, scroll to show the location
8326 bool showLocation(Rectangle rect, bool scrollPage) { 8332 bool showLocation(Rectangle rect, bool scrollPage) {
8327 int clientAreaWidth = this.clientAreaWidth - leftMargin - rightMargin; 8333 int clientAreaWidth = this.clientAreaWidth - leftMargin - rightMargin;
8328 int clientAreaHeight = this.clientAreaHeight - topMargin - bottomMargin; 8334 int clientAreaHeight = this.clientAreaHeight - topMargin - bottomMargin;
8329 bool scrolled = false; 8335 bool scrolled = false;
8330 if (rect.y <= topMargin) { 8336 if (rect.y <= topMargin) {