Skip to content

Commit

Permalink
Merge pull request #41 from teju85/single-cursor
Browse files Browse the repository at this point in the history
Single cursor support
  • Loading branch information
teju85 authored Nov 18, 2019
2 parents 2a9d0d7 + 5f41816 commit 36af0cf
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 1,128 deletions.
11 changes: 3 additions & 8 deletions src/cmds/buffer_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ DEF_CMD(
Cancel, "cancel", DEF_OP() {
auto& buf = ed.getBuff();
if(buf.isRegionActive()) buf.stopRegion();
if(buf.cursorCount() > 1) buf.clearAllCursorsButFirst();
},
DEF_HELP() { return "Cancel all multiple-cursors + active regions"; });
DEF_HELP() { return "Cancel all active regions"; });

DEF_CMD(
CopyRegion, "copy-region", DEF_OP() {
Expand All @@ -217,15 +216,11 @@ DEF_CMD(
DEF_CMD(
TextSearch, "search", DEF_OP() {
auto& buf = ed.getBuff();
if(buf.cursorCount() > 1) {
CMBAR_MSG(ed, "search works only with single cursor!\n");
return;
}
auto pos = buf.saveCursors();
auto pos = buf.getPoint();
ISearch is(ed.getWindow());
is.reset();
auto ret = ed.prompt("Search: ", nullptr, &is);
buf.gotoLine(!ret.empty()? is.getIdx() : pos[0].y, ed.getWindow().dim());
buf.gotoLine(!ret.empty()? is.getIdx() : pos.y, ed.getWindow().dim());
},
DEF_HELP() { return "Search and jump to the matching location."; });

Expand Down
29 changes: 0 additions & 29 deletions src/cmds/cursor_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,5 @@ DEF_CMD(
},
DEF_HELP() { return "Jump to the specified line number"; });

DEF_CMD(
AddCursorDown, "add-cursor-down", DEF_OP() {
auto& buf = ed.getBuff();
auto count = buf.cursorCount();
auto pos = buf.cursorAt(count - 1);
if(pos.y >= buf.length()) {
CMBAR_MSG(ed, "add-cursor-down: reached end of buffer!\n");
return;
}
++pos.y;
pos.x = std::min(buf.at(pos.y).length(), pos.x);
buf.addCursorFromBack(pos);
},
DEF_HELP() { return "Adds a cursor at the next line."; });

DEF_CMD(
AddCursorUp, "add-cursor-up", DEF_OP() {
auto& buf = ed.getBuff();
auto pos = buf.cursorAt(0);
if(pos.y <= 0) {
CMBAR_MSG(ed, "add-cursor-up: reached start of buffer!\n");
return;
}
--pos.y;
pos.x = std::min(buf.at(pos.y).length(), pos.x);
buf.addCursorFromFront(pos);
},
DEF_HELP() { return "Adds a cursor at the previous line."; });

} // end namespace CursorOps
} // end namespace teditor
16 changes: 8 additions & 8 deletions src/cmds/dir_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace DirMode {
DEF_CMD(
OpenFile, "dirmode-open-file", DEF_OP() {
auto& buf = ed.getBuff();
auto locs = buf.saveCursors();
auto file = buf.dirModeGetFileAtLine(locs[0].y);
const auto& cu = buf.getPoint();
auto file = buf.dirModeGetFileAtLine(cu.y);
auto& dir = buf.getFileName();
if(file == "." || file.empty()) return;
if(file == "..") {
Expand All @@ -24,8 +24,8 @@ DEF_CMD(
DEF_CMD(
CopyFile, "dirmode-copy-file", DEF_OP() {
auto& buf = ed.getBuff();
auto locs = buf.saveCursors();
auto file = buf.dirModeGetFileAtLine(locs[0].y);
const auto& cu = buf.getPoint();
auto file = buf.dirModeGetFileAtLine(cu.y);
auto& dir = buf.getFileName();
if(isCurrentOrParentDir(file) || file.empty()) return;
file = rel2abs(dir, file);
Expand All @@ -47,8 +47,8 @@ DEF_CMD(
DEF_CMD(
RenameFile, "dirmode-rename-file", DEF_OP() {
auto& buf = ed.getBuff();
auto locs = buf.saveCursors();
auto file = buf.dirModeGetFileAtLine(locs[0].y);
const auto& cu = buf.getPoint();
auto file = buf.dirModeGetFileAtLine(cu.y);
auto& dir = buf.getFileName();
if(isCurrentOrParentDir(file) || file.empty()) return;
file = rel2abs(dir, file);
Expand All @@ -69,8 +69,8 @@ DEF_CMD(
DeleteFile, "dirmode-delete-file", DEF_OP() {
auto& buf = ed.getBuff();
auto& dir = buf.getFileName();
auto locs = buf.saveCursors();
auto file = buf.dirModeGetFileAtLine(locs[0].y);
const auto& cu = buf.getPoint();
auto file = buf.dirModeGetFileAtLine(cu.y);
if(isCurrentOrParentDir(file) || file.empty()) return;
auto delFile = rel2abs(dir, file);
if(delFile.empty()) return;
Expand Down
6 changes: 3 additions & 3 deletions src/cmds/editor_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ DEF_CMD(
command = args.browserCmd + " '" + command + "'";
// we'll only look at first cursor!
auto query = ed.getBuff().regionAsStr();
auto queryStr = query.empty()? ed.prompt("Query: ") : query[0];
if(queryStr.empty()) return;
auto hexified = urlHexify(queryStr);
if (query.empty()) query = ed.prompt("Query: ");
if(query.empty()) return;
auto hexified = urlHexify(query);
auto buf = format(command.c_str(), hexified.c_str());
check_output(buf.c_str());
},
Expand Down
Loading

0 comments on commit 36af0cf

Please sign in to comment.