improved cursor handling in text editor

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@121 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-12-19 15:17:22 +00:00
parent 99e8f516be
commit d3c5335fc7
11 changed files with 249 additions and 98 deletions
+17 -13
View File
@@ -10,6 +10,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/tagged_string.hpp> // for Movement
#include <gui/value/editor.hpp>
#include <render/value/text.hpp>
@@ -17,11 +18,9 @@ class TextValueEditorScrollBar;
// ----------------------------------------------------------------------------- : TextValueEditor
/// Directions of cursor movement
enum Movement
{ MOVE_LEFT ///< Always move the cursor to the left
, MOVE_MID ///< Move in whichever direction the distance to move is shorter (TODO: define shorter)
, MOVE_RIGHT ///< Always move the cursor to the right
enum IndexType
{ TYPE_CURSOR ///< Positions are cursor positions
, TYPE_INDEX ///< Positions are character indices
};
/// An editor 'control' for editing TextValues
@@ -83,16 +82,19 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
// --------------------------------------------------- : Data
private:
size_t selection_start, selection_end; ///< Cursor position/selection (if any)
size_t selection_start, selection_end; ///< Cursor position/selection (if any), cursor positions
size_t selection_start_i, selection_end_i; ///< Cursor position/selection, character indices
TextValueEditorScrollBar* scrollbar; ///< Scrollbar for multiline fields in native look
bool select_words; ///< Select whole words when dragging the mouse?
// --------------------------------------------------- : Selection / movement
/// Move the selection to a new location, clears the previously drawn selection
void moveSelection(size_t new_end, bool also_move_start=true, Movement dir = MOVE_MID);
/// Move the selection to a new location, but does not redraw
void moveSelectionNoRedraw(size_t new_end, bool also_move_start=true, Movement dir = MOVE_MID);
/// Move the selection to a new location, clears the previously drawn selection.
/** t specifies what kind of position new_end is */
void moveSelection(IndexType t, size_t new_end, bool also_move_start=true, Movement dir = MOVE_MID);
/// Move the selection to a new location, but does not redraw.
/** t specifies what kind of position new_end is */
void moveSelectionNoRedraw(IndexType t, size_t new_end, bool also_move_start=true, Movement dir = MOVE_MID);
/// Replace the current selection with 'replacement', name the action
void replaceSelection(const String& replacement, const String& name);
@@ -104,7 +106,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
*
* When correcting the selection, move in the given direction
*/
void fixSelection(Movement dir = MOVE_MID);
void fixSelection(IndexType t = TYPE_CURSOR, Movement dir = MOVE_MID);
/// Return a position resulting from moving pos outside the range [start...end), in the direction dir
static size_t move(size_t pos, size_t start, size_t end, Movement dir);
@@ -113,11 +115,13 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
void showCaret();
/// Position of previous visible & selectable character
/** Uses cursor positions */
size_t prevCharBoundry(size_t pos) const;
size_t nextCharBoundry(size_t pos) const;
/// Front of previous word, used witch Ctrl+Left/right
size_t prevWordBoundry(size_t pos) const;
size_t nextWordBoundry(size_t pos) const;
/** Uses character indices */
size_t prevWordBoundry(size_t pos_i) const;
size_t nextWordBoundry(size_t pos_i) const;
// --------------------------------------------------- : Scrolling