Add g. command to go to the last buffer modification position

This commit is contained in:
Maxime Coste 2014-04-07 23:39:12 +01:00
parent a387e7a4c6
commit 33de42610d
4 changed files with 31 additions and 10 deletions

View File

@ -245,6 +245,8 @@ Commands begining with g are used to goto certain position and or buffer:
* _ga_: go to the previous (alternate) buffer * _ga_: go to the previous (alternate) buffer
* _gf_: open the file whose name is selected * _gf_: open the file whose name is selected
* _g._: go to last buffer modifiction position
View commands View commands
------------- -------------

View File

@ -715,4 +715,11 @@ void Buffer::run_hook_in_own_context(const String& hook_name, const String& para
m_hooks.run_hook(hook_name, param, hook_handler.context()); m_hooks.run_hook(hook_name, param, hook_handler.context());
} }
BufferCoord Buffer::last_modification_coord() const
{
if (m_history.empty())
return {};
return m_history.back().back().coord;
}
} }

View File

@ -136,6 +136,8 @@ public:
bool is_valid(BufferCoord c) const; bool is_valid(BufferCoord c) const;
bool is_end(BufferCoord c) const; bool is_end(BufferCoord c) const;
BufferCoord last_modification_coord() const;
BufferIterator begin() const; BufferIterator begin() const;
BufferIterator end() const; BufferIterator end() const;
ByteCount byte_count() const; ByteCount byte_count() const;

View File

@ -315,18 +315,28 @@ void goto_commands(Context& context, int line)
CommandManager::instance().execute("edit '" + path + "'", context); CommandManager::instance().execute("edit '" + path + "'", context);
break; break;
} }
case '.':
{
context.push_jump();
auto pos = buffer.last_modification_coord();
if (buffer[pos.line].length() == pos.column + 1)
pos = BufferCoord{ pos.line+1, 0 };
select_coord<mode>(buffer, pos, context.selections());
break;
}
} }
}, "goto", }, "goto",
"g,k: buffer top \n" "g,k: buffer top \n"
"l: line end \n" "l: line end \n"
"h: line begin \n" "h: line begin \n"
"j: buffer bottom\n" "j: buffer bottom \n"
"e: buffer end \n" "e: buffer end \n"
"t: window top \n" "t: window top \n"
"b: window bottom\n" "b: window bottom \n"
"c: window center\n" "c: window center \n"
"a: last buffer \n" "a: last buffer \n"
"f: file \n"); "f: file \n"
".: last buffer change\n");
} }
} }