/** * Returns whether the given offset is inside a multi byte line delimiter. * Example: * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true * * @return true if the given offset is inside a multi byte line delimiter. * false if the given offset is before or after a line delimiter. */ boolean isLineDelimiter(int offset) { int line = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(line); int offsetInLine = offset - lineOffset; // offsetInLine will be greater than line length if the line // delimiter is longer than one character and the offset is set // in between parts of the line delimiter. return offsetInLine > content.getLine(line).length(); } /**
int getWordNext (int offset, int movement, boolean ignoreListener) { int newOffset, lineOffset; String lineText; if (offset >= getCharCount()) { newOffset = offset; int lineIndex = content.getLineCount() - 1; lineOffset = content.getOffsetAtLine(lineIndex); lineText = content.getLine(lineIndex); } else { int lineIndex = content.getLineAtOffset(offset); lineOffset = content.getOffsetAtLine(lineIndex); lineText = content.getLine(lineIndex); int lineLength = lineText.length(); if (offset >= lineOffset + lineLength) { newOffset = content.getOffsetAtLine(lineIndex + 1); } else { TextLayout layout = renderer.getTextLayout(lineIndex); newOffset = lineOffset + layout.getNextOffset(offset - lineOffset, movement); renderer.disposeTextLayout(layout); } } if (ignoreListener) return newOffset; return sendWordBoundaryEvent(ST.WordNext, movement, offset, newOffset, lineText, lineOffset); } int getWordPrevious(int offset, int movement) {
int getHeight () { int defaultLineHeight = getLineHeight(); if (styledText.isFixedLineHeight()) { return lineCount * defaultLineHeight + styledText.topMargin + styledText.bottomMargin; } int totalHeight = 0; int width = styledText.getWrapWidth(); for (int i = 0; i < lineCount; i++) { int height = lineHeight[i]; if (height == -1) { if (width > 0) { int length = content.getLine(i).length(); height = ((length * averageCharWidth / width) + 1) * defaultLineHeight; } else { height = defaultLineHeight; } } totalHeight += height; } return totalHeight + styledText.topMargin + styledText.bottomMargin; } boolean hasLink(int offset) {
/** * Returns whether the given offset is inside a multi byte line delimiter. * Example: * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true * * @return true if the given offset is inside a multi byte line delimiter. * false if the given offset is before or after a line delimiter. */ boolean isLineDelimiter(int offset) { int line = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(line); int offsetInLine = offset - lineOffset; // offsetInLine will be greater than line length if the line // delimiter is longer than one character and the offset is set // in between parts of the line delimiter. return offsetInLine > content.getLine(line).length(); } /**
int getHeight () { int defaultLineHeight = getLineHeight(); if (styledText.isFixedLineHeight()) { return lineCount * defaultLineHeight + styledText.topMargin + styledText.bottomMargin; } int totalHeight = 0; int width = styledText.getWrapWidth(); for (int i = 0; i < lineCount; i++) { int height = lineHeight[i]; if (height == -1) { if (width > 0) { int length = content.getLine(i).length(); height = ((length * averageCharWidth / width) + 1) * defaultLineHeight; } else { height = defaultLineHeight; } } totalHeight += height; } return totalHeight + styledText.topMargin + styledText.bottomMargin; } boolean hasLink(int offset) {
/** * Returns whether the given offset is inside a multi byte line delimiter. * Example: * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true * * @return true if the given offset is inside a multi byte line delimiter. * false if the given offset is before or after a line delimiter. */ boolean isLineDelimiter(int offset) { int line = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(line); int offsetInLine = offset - lineOffset; // offsetInLine will be greater than line length if the line // delimiter is longer than one character and the offset is set // in between parts of the line delimiter. return offsetInLine > content.getLine(line).length(); } /**
int getHeight () { int defaultLineHeight = getLineHeight(); if (styledText.isFixedLineHeight()) { return lineCount * defaultLineHeight + styledText.topMargin + styledText.bottomMargin; } int totalHeight = 0; int width = styledText.getWrapWidth(); for (int i = 0; i < lineCount; i++) { int height = lineHeight[i]; if (height == -1) { if (width > 0) { int length = content.getLine(i).length(); height = ((length * averageCharWidth / width) + 1) * defaultLineHeight; } else { height = defaultLineHeight; } } totalHeight += height; } return totalHeight + styledText.topMargin + styledText.bottomMargin; } boolean hasLink(int offset) {
/** * Returns whether the given offset is inside a multi byte line delimiter. * Example: * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true * * @return true if the given offset is inside a multi byte line delimiter. * false if the given offset is before or after a line delimiter. */ boolean isLineDelimiter(int offset) { int line = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(line); int offsetInLine = offset - lineOffset; // offsetInLine will be greater than line length if the line // delimiter is longer than one character and the offset is set // in between parts of the line delimiter. return offsetInLine > content.getLine(line).length(); } /**
int getCaretDirection() { if (!isBidiCaret()) return SWT.DEFAULT; if (ime.getCompositionOffset() != -1) return SWT.DEFAULT; if (!updateCaretDirection && caretDirection != SWT.NULL) return caretDirection; updateCaretDirection = false; int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); String line = content.getLine(caretLine); int offset = caretOffset - lineOffset; int lineLength = line.length(); if (lineLength == 0) return isMirrored() ? SWT.RIGHT : SWT.LEFT; if (caretAlignment == PREVIOUS_OFFSET_TRAILING && offset > 0) offset--; if (offset == lineLength && offset > 0) offset--; while (offset > 0 && Character.isDigit(line.charAt(offset))) offset--; if (offset == 0 && Character.isDigit(line.charAt(offset))) { return isMirrored() ? SWT.RIGHT : SWT.LEFT; } TextLayout layout = renderer.getTextLayout(caretLine); int level = layout.getLevel(offset); renderer.disposeTextLayout(layout); return ((level & 1) != 0) ? SWT.RIGHT : SWT.LEFT; } /*
/** * Returns whether the given offset is inside a multi byte line delimiter. * Example: * "Line1\r\n" isLineDelimiter(5) == false but isLineDelimiter(6) == true * * @return true if the given offset is inside a multi byte line delimiter. * false if the given offset is before or after a line delimiter. */ boolean isLineDelimiter(int offset) { int line = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(line); int offsetInLine = offset - lineOffset; // offsetInLine will be greater than line length if the line // delimiter is longer than one character and the offset is set // in between parts of the line delimiter. return offsetInLine > content.getLine(line).length(); } /**
/** * Moves the caret to the end of the line. */ void doLineEnd() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int lineEndOffset; if (wordWrap || visualWrap) { TextLayout layout = renderer.getTextLayout(caretLine); int offsetInLine = caretOffset - lineOffset; int lineIndex = getVisualLineIndex(layout, offsetInLine); int[] offsets = layout.getLineOffsets(); lineEndOffset = lineOffset + offsets[lineIndex + 1]; renderer.disposeTextLayout(layout); } else { int lineLength = content.getLine(caretLine).length(); lineEndOffset = lineOffset + lineLength; } setCaretOffset(lineEndOffset, PREVIOUS_OFFSET_TRAILING); showCaret(); } /**
Rectangle getBoundsAtOffset(int offset) { int lineIndex = content.getLineAtOffset(offset); int lineOffset = content.getOffsetAtLine(lineIndex); String line = content.getLine(lineIndex); Rectangle bounds; if (line.length() != 0) { int offsetInLine = offset - lineOffset; TextLayout layout = renderer.getTextLayout(lineIndex); bounds = layout.getBounds(offsetInLine, offsetInLine); renderer.disposeTextLayout(layout); } else { bounds = new Rectangle (0, 0, 0, renderer.getLineHeight()); } if (offset == caretOffset && !wordWrap) { int lineEnd = lineOffset + line.length(); if (offset == lineEnd) { bounds.width += getCaretWidth(); } } bounds.x += leftMargin - horizontalScrollOffset; bounds.y += getLinePixel(lineIndex); return bounds; } /**
/** * Moves the caret to the end of the line. */ void doLineEnd() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int lineEndOffset; if (wordWrap || visualWrap) { TextLayout layout = renderer.getTextLayout(caretLine); int offsetInLine = caretOffset - lineOffset; int lineIndex = getVisualLineIndex(layout, offsetInLine); int[] offsets = layout.getLineOffsets(); lineEndOffset = lineOffset + offsets[lineIndex + 1]; renderer.disposeTextLayout(layout); } else { int lineLength = content.getLine(caretLine).length(); lineEndOffset = lineOffset + lineLength; } setCaretOffset(lineEndOffset, PREVIOUS_OFFSET_TRAILING); showCaret(); } /**
/** * Deletes the next character. Delete the selected text if any. */ void doDelete() { Event event = new Event(); event.text = ""; if (selection.x != selection.y) { event.start = selection.x; event.end = selection.y; sendKeyEvent(event); } else if (caretOffset < content.getCharCount()) { int line = content.getLineAtOffset(caretOffset); int lineOffset = content.getOffsetAtLine(line); int lineLength = content.getLine(line).length(); if (caretOffset == lineOffset + lineLength) { event.start = caretOffset; event.end = content.getOffsetAtLine(line + 1); } else { event.start = caretOffset; event.end = getClusterNext(caretOffset, line); } sendKeyEvent(event); } } /**
/** * Moves the caret to the previous character or to the end of the previous * line if the cursor is at the beginning of a line. */ void doSelectionCursorPrevious() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; if (offsetInLine > 0) { int offset = getClusterPrevious(caretOffset, caretLine); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); int offset = lineOffset + content.getLine(caretLine).length(); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } } /**
/** * Deletes the next character. Delete the selected text if any. */ void doDelete() { Event event = new Event(); event.text = ""; if (selection.x != selection.y) { event.start = selection.x; event.end = selection.y; sendKeyEvent(event); } else if (caretOffset < content.getCharCount()) { int line = content.getLineAtOffset(caretOffset); int lineOffset = content.getOffsetAtLine(line); int lineLength = content.getLine(line).length(); if (caretOffset == lineOffset + lineLength) { event.start = caretOffset; event.end = content.getOffsetAtLine(line + 1); } else { event.start = caretOffset; event.end = getClusterNext(caretOffset, line); } sendKeyEvent(event); } } /**
/** * Moves the caret to the previous character or to the end of the previous * line if the cursor is at the beginning of a line. */ void doSelectionCursorPrevious() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; if (offsetInLine > 0) { int offset = getClusterPrevious(caretOffset, caretLine); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); int offset = lineOffset + content.getLine(caretLine).length(); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } } /**
/** * Moves the caret to the previous character or to the end of the previous * line if the cursor is at the beginning of a line. */ void doSelectionCursorPrevious() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; if (offsetInLine > 0) { int offset = getClusterPrevious(caretOffset, caretLine); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); int offset = lineOffset + content.getLine(caretLine).length(); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } } /**
/** * Moves the caret to the previous character or to the end of the previous * line if the cursor is at the beginning of a line. */ void doSelectionCursorPrevious() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; if (offsetInLine > 0) { int offset = getClusterPrevious(caretOffset, caretLine); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); int offset = lineOffset + content.getLine(caretLine).length(); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } } /**
/** * Moves the caret to the previous character or to the end of the previous * line if the cursor is at the beginning of a line. */ void doSelectionCursorPrevious() { int caretLine = getCaretLine(); int lineOffset = content.getOffsetAtLine(caretLine); int offsetInLine = caretOffset - lineOffset; if (offsetInLine > 0) { int offset = getClusterPrevious(caretOffset, caretLine); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } else if (caretLine > 0) { caretLine--; lineOffset = content.getOffsetAtLine(caretLine); int offset = lineOffset + content.getLine(caretLine).length(); setCaretOffset(offset, OFFSET_LEADING); showCaret(); } } /**