return length;
}
-
-int ME_SetSelection(ME_TextEditor *editor, int from, int to)
+/******************************************************************
+ * set_selection_cursors
+ *
+ * Updates the selection cursors.
+ *
+ * Note that this does not invalidate either the old or the new selections.
+ */
+int set_selection_cursors(ME_TextEditor *editor, int from, int to)
{
int selectionEnd = 0;
const int len = ME_GetTextLength(editor);
{
ME_SetCursorToStart(editor, &editor->pCursors[1]);
ME_SetCursorToEnd(editor, &editor->pCursors[0], TRUE);
- ME_InvalidateSelection(editor);
return len + 1;
}
end --;
}
editor->pCursors[1] = editor->pCursors[0];
- ME_Repaint(editor);
}
return end;
}
{
ME_SetCursorToEnd(editor, &editor->pCursors[0], FALSE);
editor->pCursors[1] = editor->pCursors[0];
- ME_InvalidateSelection(editor);
return len;
}
return;
}
-
-void
-ME_MoveCaret(ME_TextEditor *editor)
+void create_caret(ME_TextEditor *editor)
{
int x, y, height;
ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height);
- if(editor->bHaveFocus && !ME_IsSelection(editor))
- {
- x = min(x, editor->rcFormat.right-1);
- ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
- ITextHost_TxSetCaretPos(editor->texthost, x, y);
- }
+ ITextHost_TxCreateCaret(editor->texthost, NULL, 0, height);
+ editor->caret_height = height;
+ editor->caret_hidden = TRUE;
}
+void show_caret(ME_TextEditor *editor)
+{
+ ITextHost_TxShowCaret(editor->texthost, TRUE);
+ editor->caret_hidden = FALSE;
+}
-void ME_ShowCaret(ME_TextEditor *ed)
+void hide_caret(ME_TextEditor *editor)
{
- ME_MoveCaret(ed);
- if(ed->bHaveFocus && !ME_IsSelection(ed))
- ITextHost_TxShowCaret(ed->texthost, TRUE);
+ /* calls to HideCaret are cumulative; do so only once */
+ if (!editor->caret_hidden)
+ {
+ ITextHost_TxShowCaret(editor->texthost, FALSE);
+ editor->caret_hidden = TRUE;
+ }
}
-void ME_HideCaret(ME_TextEditor *ed)
+void update_caret(ME_TextEditor *editor)
{
- if(!ed->bHaveFocus || ME_IsSelection(ed))
+ int x, y, height;
+
+ if (!editor->bHaveFocus) return;
+ if (!ME_IsSelection(editor))
{
- ITextHost_TxShowCaret(ed->texthost, FALSE);
- DestroyCaret();
+ ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x, &y, &height);
+ if (height != editor->caret_height) create_caret(editor);
+ x = min(x, editor->rcFormat.right-1);
+ ITextHost_TxSetCaretPos(editor->texthost, x, y);
+ show_caret(editor);
}
+ else
+ hide_caret(editor);
}
BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
}
}
ME_InvalidateSelection(editor);
- ITextHost_TxShowCaret(editor->texthost, FALSE);
- ME_ShowCaret(editor);
+ update_caret(editor);
ME_SendSelChange(editor);
}
}
ME_InvalidateSelection(editor);
- ITextHost_TxShowCaret(editor->texthost, FALSE);
- ME_ShowCaret(editor);
+ update_caret(editor);
ME_SendSelChange(editor);
}
ME_InvalidateSelection(editor);
ME_Repaint(editor);
- ITextHost_TxShowCaret(editor->texthost, FALSE);
+ hide_caret(editor);
ME_EnsureVisible(editor, &tmp_curs);
- ME_ShowCaret(editor);
+ update_caret(editor);
ME_SendSelChange(editor);
return success;
}