Java Code Examples for org.eclipse.swt.custom.StyledText#replaceTextRange()
The following examples show how to use
org.eclipse.swt.custom.StyledText#replaceTextRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindReplaceDialog.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 替换 ; */ private void doReplace() { CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion(); if (activeCellRegion == null) { return; } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if(cellEditor != null){ StyledText text = cellEditor.getSegmentViewer().getTextWidget(); String sleText = text.getSelectionText(); String findStr = cmbFind.getText(); if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) { findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n"); findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B"); findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B"); } if( sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())){ Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText()); } } }
Example 2
Source File: FindReplaceDialog.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 替换 ; */ private void doReplace() { CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion(); if (activeCellRegion == null) { return; } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if(cellEditor != null){ StyledText text = cellEditor.getSegmentViewer().getTextWidget(); String sleText = text.getSelectionText(); if( sleText != null && sleText.toLowerCase().equals(cmbFind.getText().toLowerCase())){ Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText()); } } }
Example 3
Source File: FindReplaceDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void replace() { if (tmxEditorImpWithNattable == null || tmxEditorImpWithNattable.isDispose()) { return; } String findStr = findTextCombo.getText(); if (findStr == null || findStr.length() == 0) { return; } String replaceStr = replaceTextCombo.getText(); if (replaceStr == null || replaceStr.length() == 0) { return; } CellEditor cellEditor = (CellEditor) TeActiveCellEditor.getCellEditor(); if (cellEditor != null) { StyledText text = cellEditor.getTextViewer().getTextWidget(); String sleText = cellEditor.getTextViewer().getSelectionText(); if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase()) && !sleText.equals(replaceStr)) { Matcher matcher = PlaceHolderEditModeBuilder.PATTERN.matcher(sleText); StringBuilder sb = new StringBuilder(); while (matcher.find()) { sb.append(matcher.group()); } sb.insert(0, replaceStr); Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, sb.toString()); text.setSelection(p.x, p.x + replaceStr.length()); TeActiveCellEditor.commitWithoutClose(); updateCombHistory(replaceTextCombo); } } }
Example 4
Source File: NewLineIndentHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent) */ @Override protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) throws BadLocationException { int result = NO_OFFSET; Control c = MarkUtils.getTextWidget(editor); if (c instanceof StyledText) { StyledText st = (StyledText)c; String ld = st.getLineDelimiter(); int insertionOffset = getCursorOffset(editor,currentSelection); int widgetInsertionOffset = st.getCaretOffset(); // the offset position will be updated by the internals on insertion/indent Position caret= new Position(insertionOffset, 0); document.addPosition(caret); st.setSelectionRange(widgetInsertionOffset, 0); // operate directly on the widget st.replaceTextRange(widgetInsertionOffset, 0, ld); document.removePosition(caret); if (st.getSelection().x == widgetInsertionOffset) { // move cursor by the amount detected result = getCursorOffset(editor) + caret.offset - insertionOffset; } } return result; }
Example 5
Source File: TestAutoClosing.java From tm4e with Eclipse Public License 1.0 | 4 votes |
@Test public void testAutoClose() throws Exception { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis()); p.create(null); p.open(null); IFile file = p.getFile("test.lc-test"); file.create(new ByteArrayInputStream(new byte[0]), true, null); ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); StyledText text = (StyledText)editor.getAdapter(Control.class); // insert closing text.setText(""); text.replaceTextRange(0, 0, "("); Assert.assertEquals("()", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // nested insert closing text.setText("foo(String::from)"); text.replaceTextRange(16, 0, "("); Assert.assertEquals("foo(String::from())", text.getText()); Assert.assertEquals(17, text.getCaretOffset()); // ignore already opened text.setText("()"); text.replaceTextRange(0, 0, "("); Assert.assertEquals("()", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // ignore already closed text.setText("()"); text.replaceTextRange(1, 0, ")"); Assert.assertEquals("()", text.getText()); Assert.assertEquals(2, text.getCaretOffset()); // text.setText("()"); text.replaceTextRange(2, 0, ")"); Assert.assertEquals("())", text.getText()); // text.setText(""); text.replaceTextRange(0, 0, "\""); Assert.assertEquals("\"\"", text.getText()); Assert.assertEquals(1, text.getCaretOffset()); // continued text.replaceTextRange(1, 0, "\""); Assert.assertEquals("\"\"", text.getText()); Assert.assertEquals(2, text.getCaretOffset()); // continued text.replaceTextRange(2, 0, "\""); Assert.assertEquals("\"\"\"\"", text.getText()); Assert.assertEquals(3, text.getCaretOffset()); }