[ease/serialize: 50/52] Cursor moving works!
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/serialize: 50/52] Cursor moving works!
- Date: Tue, 22 Feb 2011 22:57:21 +0000 (UTC)
commit db7b5f709d458c3dbd7854ad89d0b482f252be3e
Author: Nate Stedman <natesm gmail com>
Date: Sun Feb 6 17:44:48 2011 -0500
Cursor moving works!
ease-core/ease-layout.vala | 8 ++++++
ease-core/ease-text-actor.vala | 7 ++---
ease-core/ease-text.vala | 52 +++++++++++++++++++++++++++-------------
3 files changed, 46 insertions(+), 21 deletions(-)
---
diff --git a/ease-core/ease-layout.vala b/ease-core/ease-layout.vala
index 96f470b..b4b654e 100644
--- a/ease-core/ease-layout.vala
+++ b/ease-core/ease-layout.vala
@@ -107,6 +107,14 @@ public class Ease.Layout : GLib.Object
}
/**
+ * The length of the layout's text.
+ */
+ public int length
+ {
+ get { return (int)layout.get_text().length; }
+ }
+
+ /**
* The attribute list of the layout. In { link TextElement}, this is
* controlled by a master list of attributes that operates across the
* entire set of layouts.
diff --git a/ease-core/ease-text-actor.vala b/ease-core/ease-text-actor.vala
index fdab14d..df1c04b 100644
--- a/ease-core/ease-text-actor.vala
+++ b/ease-core/ease-text-actor.vala
@@ -158,8 +158,7 @@ public class Ease.TextActor : Actor
{
case Key.BACKSPACE:
text.delete(cursor_index - 1, cursor_layout);
- text.retreat_cursor(ref cursor_index,
- ref cursor_layout, 1);
+ text.move_cursor(ref cursor_index, ref cursor_layout, -1);
selection_index = cursor_index;
cursor.opacity = 255;
cursor_timeline.rewind();
@@ -173,7 +172,7 @@ public class Ease.TextActor : Actor
case Key.LEFT:
// move the cursor back
- text.retreat_cursor(ref cursor_index, ref cursor_layout, 1);
+ text.move_cursor(ref cursor_index, ref cursor_layout, -1);
selection_index = cursor_index;
selection_layout = cursor_layout;
@@ -184,7 +183,7 @@ public class Ease.TextActor : Actor
case Key.RIGHT:
// advance the cursor
- text.advance_cursor(ref cursor_index, ref cursor_layout, 1);
+ text.move_cursor(ref cursor_index, ref cursor_layout, 1);
selection_index = cursor_index;
selection_layout = cursor_layout;
diff --git a/ease-core/ease-text.vala b/ease-core/ease-text.vala
index d8024ea..794cf00 100644
--- a/ease-core/ease-text.vala
+++ b/ease-core/ease-text.vala
@@ -88,29 +88,47 @@ public class Ease.Text : GLib.Object
}
/**
- * Advances the cursor by a specified number of characters. If the cursor
- * cannot be moved forward, it will not be moved.
+ * Moves the the cursor back or forward by a specified number of characters. If the
+ * cursor cannot move the specified amount of characters, it will not move.
*
* @param index The index of the cursor, this value is set on out.
* @param layout_index The layout index, this value is set on out.
- * @param chars The number of characters to advance.
+ * @param chars The number of characters to advance or retreat.
*/
- public void advance_cursor(ref int index, ref int layout_index, uint chars)
- {
-
- }
-
- /**
- * Moves the the cursor back by a specified number of characters. If the
- * cursor cannot move back, it will not be moved.
- *
- * @param index The index of the cursor, this value is set on out.
- * @param layout_index The layout index, this value is set on out.
- * @param chars The number of characters to advance.
- */
- public void retreat_cursor(ref int index, ref int layout_index, uint chars)
+ public void move_cursor(ref int index, ref int layout_index, int chars)
{
+ var current = layouts.get(layout_index);
+ if (chars > 0)
+ {
+ if (index + chars > current.length)
+ {
+ if (layouts.size > layout_index + 1)
+ {
+ layout_index++;
+ index = index + chars - current.length;
+ }
+ }
+ else
+ {
+ index++;
+ }
+ }
+ else if (chars < 0)
+ {
+ if (index + chars < 0)
+ {
+ if (layout_index > 0)
+ {
+ layout_index--;
+ index = layouts.get(layout_index).length;
+ }
+ }
+ else
+ {
+ index--;
+ }
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]