Skip to content

Commit

Permalink
Fix copy/paste from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaughan committed Sep 4, 2023
1 parent b501860 commit 5dbaf38
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions include/zep/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ class ZepEditor
void SetRegister(const char reg, const Register& val);
void SetRegister(const std::string& reg, const char* pszText);
void SetRegister(const char reg, const char* pszText);
Register& GetRegister(const std::string& reg);
Register& GetRegister(const char reg);
const Register& GetRegister(const std::string& reg);
const Register& GetRegister(const char reg);
const tRegisters& GetRegisters();

void ReadClipboard();
Expand Down
4 changes: 2 additions & 2 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ void ZepEditor::SetRegister(const char reg, const char* pszText)
}
}

Register& ZepEditor::GetRegister(const std::string& reg)
const Register& ZepEditor::GetRegister(const std::string& reg)
{
if (reg == "+" || reg == "*")
{
Expand All @@ -1028,7 +1028,7 @@ Register& ZepEditor::GetRegister(const std::string& reg)
return m_registers[reg];
}

Register& ZepEditor::GetRegister(const char reg)
const Register& ZepEditor::GetRegister(const char reg)
{
if (reg == '+' || reg == '*')
{
Expand Down
15 changes: 8 additions & 7 deletions src/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ void CommandContext::UpdateRegisters()
void CommandContext::GetCommandRegisters()
{
// No specified register, so use the default
if (keymap.RegisterName() == 0)
{
registers.push('*');
registers.push('+');
}
else
if (keymap.RegisterName() != 0)
{
if (keymap.RegisterName() == '_')
{
Expand Down Expand Up @@ -477,16 +472,17 @@ void ZepMode::HandleMappedInput(const std::string& input)
if (spContext->commandResult.spCommand)
{
// If not in insert mode, begin the group, because we have started a new operation
// i.e. one group before adding characters and typing stuff.
if (m_currentMode != EditorMode::Insert || ZTestFlags(spContext->commandResult.flags, CommandResultFlags::BeginUndoGroup))
{
AddCommand(std::make_shared<ZepCommand_GroupMarker>(spContext->buffer));

// Record for the dot command
m_dotCommand = m_currentCommand;
}
else
{
// In insert mode keep the text for the dot command. An insert adds a command too!
// Accumulate
m_dotCommand += input;
}

Expand Down Expand Up @@ -1400,13 +1396,16 @@ bool ZepMode::GetCommand(CommandContext& context)
}
else if (mappedCommand == id_StandardPaste)
{
GetEditor().ReadClipboard();

if (context.currentMode == EditorMode::Visual)
{
auto range = GetInclusiveVisualRange();
if (!range.Valid())
{
return true;
}

context.replaceRangeMode = ReplaceRangeMode::Replace;
context.op = CommandOperation::Replace;
context.pRegister = &GetEditor().GetRegister('"');
Expand All @@ -1424,6 +1423,8 @@ bool ZepMode::GetCommand(CommandContext& context)
}
else if (mappedCommand == id_PasteAfter)
{
GetEditor().ReadClipboard();

if (!context.pRegister->text.empty())
{
// Already in visual mode, so replace the selection
Expand Down

0 comments on commit 5dbaf38

Please # to comment.