void Document :: uncommentBlock() { int selection = _selection; _selection = 0; if (selection < 0) { _caret.moveOn(selection); selection = -selection; } Point caret = _caret.getCaret(); TextBookmark end = _caret; end.moveOn(selection); text_c line[3]; while ((size_t)caret.y <= end.getRow()) { if (!_caret.moveTo(0, caret.y)) return; _text->copyTo(_caret, line, 2); if (text_str(_T("//")).compare(line, 2)) { eraseChar(false); eraseChar(false); } caret.y++; } }
int Document :: retrieveColumn(int row, int disp) { TextBookmark bm = _caret; _text->validateBookmark(bm); bm.moveTo(0, row); bm.moveOn(disp); return bm.getColumn(); }
void Document :: tabbing(text_c space, size_t count, bool indent) { _text->validateBookmark(_caret); if (_selection < 0) { _caret.moveOn(_selection); _selection = abs(_selection); } TextBookmark end = _caret; end.moveOn(_selection); // if only part of the line was selected just insert tab size_t lastRow = end.getRow(); if (lastRow == _caret.getRow()) { if (indent) insertChar(space, count); } else { setCaret(0, _caret.getRow(), true); if (end.getColumn() == 0) lastRow--; TextBookmark start = _caret; while (start.getRow() <= lastRow) { if (indent) { for (size_t i = 0 ; i < count ; i++) { _text->insertChar(start, space); _selection++; } } else { size_t length; for (size_t i = 0 ; i < count ; i++) { text_t s = _text->getLine(start, length); if (length!=0 && (s[0]==' ' || s[0]=='\t')) { bool tab = (s[0]=='\t'); _text->eraseChar(start); _selection--; if (tab) break; } else break; } } if(!start.moveTo(0, start.getRow() + 1)) break; } } }
const _text_t* SourceDoc :: getCurrentLine(int disp, size_t& length) { TextBookmark bm = _caret; bm.moveTo(0, _caret.getRow()); if (disp == 0 || bm.moveOn(disp)) { return _text->getLine(bm, length); } else { length = 0; return NULL; } }
_text_t SourceDoc :: getCurrentChar() { size_t length = 0; const _text_t* line = NULL; TextBookmark bm = _caret; // return current or previous if EOL if (!bm.isEOL()) { line = _text->getLine(bm, length); } else { if (bm.moveOn(-1)) line = _text->getLine(bm, length); } return (length > 0) ? line[0] : 0; }
void Document :: commentBlock() { int selection = _selection; _selection = 0; if (selection < 0) { _caret.moveOn(selection); selection = -selection; } Point caret = _caret.getCaret(); TextBookmark end = _caret; end.moveOn(selection); while ((size_t)caret.y < end.getRow() || ((size_t)caret.y == end.getRow() && end.getColumn() > 0)) { if (!_caret.moveTo(0, caret.y)) return; insertLine(_T("//"), 2); caret.y++; } }