Commit 488aa15d authored by twanvl's avatar twanvl

correct cursor movement after typing

parent 7090b6cd
......@@ -224,7 +224,15 @@ void TextValueEditor::onMenu(wxCommandEvent& ev) {
void TextValueEditor::draw(RotatedDC& dc) {
TextValueViewer::draw(dc);
v.drawSelection(dc, style(), selection_start, selection_end);
if (isCurrent()) {
v.drawSelection(dc, style(), selection_start, selection_end);
// show caret, onAction() would be a better place
// but it has to be done after the viewer has updated the TextViewer
// we could do that ourselfs, but we need a dc for that
fixSelection();
showCaret();
}
// DEBUG, TODO: REMOVEME
Rotater r(dc, style().getRotation());
/*dc.SetPen(*wxRED_PEN);
......@@ -269,8 +277,6 @@ void TextValueEditor::onAction(const ValueAction& action, bool undone) {
TYPE_CASE(action, TextValueAction) {
selection_start = action.selection_start;
selection_end = action.selection_end;
fixSelection();
if (isCurrent()) showCaret();
}
}
......@@ -437,6 +443,8 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
moveSelection(selection_start);
return;
}
// perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text
getSet().actions.add(action);
// move cursor
if (field().move_cursor_with_sort && replacement.size() == 1) {
......
......@@ -64,13 +64,9 @@ TextViewer::~TextViewer() {}
// ----------------------------------------------------------------------------- : Drawing
void TextViewer::draw(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx, DrawWhat what) {
void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) {
assert(!lines.empty());
Rotater r(dc, style.getRotation());
if (lines.empty()) {
// not prepared yet
prepareElements(text, style, ctx);
prepareLines(dc, text, style);
}
// Draw the text line by line
FOR_EACH(l, lines) {
if (l.visible(dc)) {
......@@ -102,6 +98,14 @@ void TextViewer::Line::drawSelection(RotatedDC& dc, size_t sel_start, size_t sel
}
}
void TextViewer::prepare(RotatedDC& dc, const String& text, const TextStyle& style, Context& ctx) {
if (lines.empty()) {
// not prepared yet
Rotater r(dc, style.getRotation());
prepareElements(text, style, ctx);
prepareLines(dc, text, style);
}
}
void TextViewer::reset() {
elements.clear();
lines.clear();
......
......@@ -47,10 +47,12 @@ class TextViewer {
/** The drawing information is cached,
* before calling draw again with different text/style reset() should be called
*/
void draw(RotatedDC& dc, const String& text, const TextStyle& style, Context&, DrawWhat);
void draw(RotatedDC& dc, const TextStyle& style, DrawWhat what);
/// Draw an indicator for selected text
void drawSelection(RotatedDC& dc, const TextStyle& style, size_t sel_start, size_t sel_end);
/// Prepare the text for drawing, if it is not already prepared
void prepare(RotatedDC& dc, const String& text, const TextStyle& style, Context&);
/// Reset the cached data, at a new call to draw it will be recalculated
void reset();
......
......@@ -13,7 +13,8 @@
void TextValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
v.draw(dc, value().value(), style(), viewer.getContext(), DRAW_NORMAL);
v.prepare(dc, value().value(), style(), viewer.getContext());
v.draw(dc, style(), DRAW_NORMAL);
}
void TextValueViewer::onValueChange() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment