/** * Checks whether the selection & caret is inside editable text, and changes their positions * accordingly if not. */ void checkAndFixCaret() { Document3 doc = getOmDocument(); if (doc == null) { // doc is not active return; } if (!doc.isEditMode()) { return; } // int pos = m_editor.getCaretPosition(); int spos = getSelectionStart(); int epos = getSelectionEnd(); /* * int start = m_segmentStartOffset + m_sourceDisplayLength + * OConsts.segmentStartStringFull.length(); */ int start = doc.getTranslationStart(); // -1 for space before tag, -2 for newlines /* * int end = editor.getTextLength() - m_segmentEndInset - * OConsts.segmentEndStringFull.length(); */ int end = doc.getTranslationEnd(); if (spos != epos) { // dealing with a selection here - make sure it's w/in bounds if (spos < start) { fixSelectionStart(start); } else if (spos > end) { fixSelectionStart(end); } if (epos > end) { fixSelectionEnd(end); } else if (epos < start) { fixSelectionStart(start); } } else { // non selected text if (spos < start) { setCaretPosition(start); } else if (spos > end) { setCaretPosition(end); } } }