Changeset View
Changeset View
Standalone View
Standalone View
commands/tools/selection/text/kpToolTextEnterCommand.cpp
Show All 39 Lines | 39 | kpToolTextEnterCommand::kpToolTextEnterCommand (const QString &name, | |||
---|---|---|---|---|---|
40 | int row, int col, Action action, | 40 | int row, int col, Action action, | ||
41 | kpCommandEnvironment *environ) | 41 | kpCommandEnvironment *environ) | ||
42 | : kpNamedCommand (name, environ), | 42 | : kpNamedCommand (name, environ), | ||
43 | m_row (row), m_col (col), | 43 | m_row (row), m_col (col), | ||
44 | m_numEnters (0) | 44 | m_numEnters (0) | ||
45 | { | 45 | { | ||
46 | viewManager ()->setTextCursorPosition (m_row, m_col); | 46 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
47 | 47 | | |||
48 | if (action == AddEnterNow) | 48 | if (action == AddEnterNow) { | ||
49 | addEnter (); | 49 | addEnter (); | ||
50 | } | 50 | } | ||
51 | | ||||
52 | kpToolTextEnterCommand::~kpToolTextEnterCommand () | | |||
53 | { | | |||
54 | } | 51 | } | ||
55 | 52 | | |||
53 | kpToolTextEnterCommand::~kpToolTextEnterCommand () = default; | ||||
54 | | ||||
56 | 55 | | |||
57 | // public | 56 | // public | ||
58 | void kpToolTextEnterCommand::addEnter () | 57 | void kpToolTextEnterCommand::addEnter () | ||
59 | { | 58 | { | ||
60 | QList <QString> textLines = textSelection ()->textLines (); | 59 | QList <QString> textLines = textSelection ()->textLines (); | ||
61 | 60 | | |||
62 | const QString rightHalf = textLines [m_row].mid (m_col); | 61 | const QString rightHalf = textLines [m_row].mid (m_col); | ||
63 | 62 | | |||
Show All 20 Lines | |||||
84 | 83 | | |||
85 | // public virtual [base kpCommand] | 84 | // public virtual [base kpCommand] | ||
86 | void kpToolTextEnterCommand::execute () | 85 | void kpToolTextEnterCommand::execute () | ||
87 | { | 86 | { | ||
88 | viewManager ()->setTextCursorPosition (m_row, m_col); | 87 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
89 | int oldNumEnters = m_numEnters; | 88 | int oldNumEnters = m_numEnters; | ||
90 | m_numEnters = 0; | 89 | m_numEnters = 0; | ||
91 | 90 | | |||
92 | for (int i = 0; i < oldNumEnters; i++) | 91 | for (int i = 0; i < oldNumEnters; i++) { | ||
93 | addEnter (); | 92 | addEnter (); | ||
94 | } | 93 | } | ||
94 | } | ||||
95 | 95 | | |||
96 | // public virtual [base kpCommand] | 96 | // public virtual [base kpCommand] | ||
97 | void kpToolTextEnterCommand::unexecute () | 97 | void kpToolTextEnterCommand::unexecute () | ||
98 | { | 98 | { | ||
99 | viewManager ()->setTextCursorPosition (m_row, m_col); | 99 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
100 | 100 | | |||
101 | QList <QString> textLines = textSelection ()->textLines (); | 101 | QList <QString> textLines = textSelection ()->textLines (); | ||
102 | 102 | | |||
103 | for (int i = 0; i < m_numEnters; i++) | 103 | for (int i = 0; i < m_numEnters; i++) | ||
104 | { | 104 | { | ||
105 | Q_ASSERT (m_col == 0); | 105 | Q_ASSERT (m_col == 0); | ||
106 | 106 | | |||
107 | if (m_row <= 0) | 107 | if (m_row <= 0) { | ||
108 | break; | 108 | break; | ||
109 | } | ||||
109 | 110 | | |||
110 | int newRow = m_row - 1; | 111 | int newRow = m_row - 1; | ||
111 | int newCol = textLines [newRow].length (); | 112 | int newCol = textLines [newRow].length (); | ||
112 | 113 | | |||
113 | textLines [newRow] += textLines [m_row]; | 114 | textLines [newRow] += textLines [m_row]; | ||
114 | 115 | | |||
115 | textLines.erase (textLines.begin () + m_row); | 116 | textLines.erase (textLines.begin () + m_row); | ||
116 | 117 | | |||
Show All 9 Lines |