From f7c358319ecfc088c8fe2efbb45542f62c5d22b6 Mon Sep 17 00:00:00 2001 From: fox0430 Date: Wed, 15 May 2019 00:10:13 +0900 Subject: [PATCH 1/4] Fix #287 --- src/moepkg/visualmode.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moepkg/visualmode.nim b/src/moepkg/visualmode.nim index 11836fb0c..f2e2e0453 100644 --- a/src/moepkg/visualmode.nim +++ b/src/moepkg/visualmode.nim @@ -72,7 +72,7 @@ proc yankBuffer(status: var EditorStatus, area: SelectArea) = status.registers.yankedLines.add(status.bufStatus[status.currentBuffer].buffer[i]) proc deleteBuffer(status: var EditorStatus, area: SelectArea) = - if status.bufStatus[status.currentBuffer].buffer.len == 1 and status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return + if status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return yankBuffer(status, area) for i in area.startLine .. area.endLine: From 01d9d9a1db45a00c2aed305fd83998e1d2d67ade Mon Sep 17 00:00:00 2001 From: fox0430 Date: Wed, 15 May 2019 01:00:09 +0900 Subject: [PATCH 2/4] Revert "Fix #287" This reverts commit f7c358319ecfc088c8fe2efbb45542f62c5d22b6. --- src/moepkg/visualmode.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/moepkg/visualmode.nim b/src/moepkg/visualmode.nim index f2e2e0453..11836fb0c 100644 --- a/src/moepkg/visualmode.nim +++ b/src/moepkg/visualmode.nim @@ -72,7 +72,7 @@ proc yankBuffer(status: var EditorStatus, area: SelectArea) = status.registers.yankedLines.add(status.bufStatus[status.currentBuffer].buffer[i]) proc deleteBuffer(status: var EditorStatus, area: SelectArea) = - if status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return + if status.bufStatus[status.currentBuffer].buffer.len == 1 and status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return yankBuffer(status, area) for i in area.startLine .. area.endLine: From 924c5f641fc551c2f63175b4afab56ffc028d83d Mon Sep 17 00:00:00 2001 From: fox0430 Date: Wed, 15 May 2019 12:50:39 +0900 Subject: [PATCH 3/4] Fix visual mode bug --- src/moepkg/visualmode.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/moepkg/visualmode.nim b/src/moepkg/visualmode.nim index 11836fb0c..429e53d52 100644 --- a/src/moepkg/visualmode.nim +++ b/src/moepkg/visualmode.nim @@ -53,6 +53,7 @@ proc swapSlectArea(area: var SelectArea) = swap(area.startColumn, area.endColumn) proc yankBuffer(status: var EditorStatus, area: SelectArea) = + if status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return status.registers.yankedLines = @[] status.registers.yankedStr = @[] @@ -76,7 +77,7 @@ proc deleteBuffer(status: var EditorStatus, area: SelectArea) = yankBuffer(status, area) for i in area.startLine .. area.endLine: - if area.startLine == area.endLine: + if area.startLine == area.endLine and status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len > 1: for j in area.startColumn .. area.endColumn: status.bufStatus[status.currentBuffer].buffer[area.startLine].delete(area.startColumn) elif i == area.startLine and area.startColumn > 0: @@ -91,7 +92,8 @@ proc deleteBuffer(status: var EditorStatus, area: SelectArea) = status.bufStatus[status.currentBuffer].buffer.delete(area.startLine, area.startLine + 1) inc(status.bufStatus[status.currentBuffer].countChange) - status.bufStatus[status.currentBuffer].currentLine = area.startLine + if area.startLine > status.bufStatus[status.currentBuffer].buffer.high: status.bufStatus[status.currentBuffer].currentLine = status.bufStatus[status.currentBuffer].buffer.high + else: status.bufStatus[status.currentBuffer].currentLine = area.startLine status.bufStatus[status.currentBuffer].currentColumn = area.startColumn status.bufStatus[status.currentBuffer].expandedColumn = area.startColumn From 8542291cdf37b0fe86a3f50e534ad07a14578494 Mon Sep 17 00:00:00 2001 From: fox0430 Date: Fri, 17 May 2019 01:23:36 +0900 Subject: [PATCH 4/4] Fix some visual mode bug and refactor --- src/moepkg/visualmode.nim | 71 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/moepkg/visualmode.nim b/src/moepkg/visualmode.nim index 429e53d52..d77fc6452 100644 --- a/src/moepkg/visualmode.nim +++ b/src/moepkg/visualmode.nim @@ -52,50 +52,49 @@ proc swapSlectArea(area: var SelectArea) = swap(area.startLine, area.endLine) swap(area.startColumn, area.endColumn) -proc yankBuffer(status: var EditorStatus, area: SelectArea) = - if status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return - status.registers.yankedLines = @[] - status.registers.yankedStr = @[] +proc yankBuffer(bufStatus: var BufferStatus, registers: var Registers, area: SelectArea) = + if bufStatus.buffer[bufStatus.currentLine].len < 1: return + registers.yankedLines = @[] + registers.yankedStr = @[] for i in area.startLine .. area.endLine: if area.startLine == area.endLine: - for j in area.startColumn .. area.endColumn: - status.registers.yankedStr.add(status.bufStatus[status.currentBuffer].buffer[area.startLine][j]) + for j in area.startColumn .. area.endColumn: registers.yankedStr.add(bufStatus.buffer[area.startLine][j]) if i == area.startLine and area.startColumn > 0: - status.registers.yankedLines.add(ru"") - for j in area.startColumn ..< status.bufStatus[status.currentBuffer].buffer[area.startLine].len: - status.registers.yankedLines[status.registers.yankedLines.high].add(status.bufStatus[status.currentBuffer].buffer[area.startLine][j]) - elif i == area.endLine and area.endColumn < status.bufStatus[status.currentBuffer].buffer[area.endLine].len: - status.registers.yankedLines.add(ru"") + registers.yankedLines.add(ru"") + for j in area.startColumn ..< bufStatus.buffer[area.startLine].len: + registers.yankedLines[registers.yankedLines.high].add(bufStatus.buffer[area.startLine][j]) + elif i == area.endLine and area.endColumn < bufStatus.buffer[area.endLine].len: + registers.yankedLines.add(ru"") for j in 0 .. area.endColumn: - status.registers.yankedLines[status.registers.yankedLines.high].add(status.bufStatus[status.currentBuffer].buffer[area.endLine][j]) + registers.yankedLines[registers.yankedLines.high].add(bufStatus.buffer[area.endLine][j]) else: - status.registers.yankedLines.add(status.bufStatus[status.currentBuffer].buffer[i]) + registers.yankedLines.add(bufStatus.buffer[i]) -proc deleteBuffer(status: var EditorStatus, area: SelectArea) = - if status.bufStatus[status.currentBuffer].buffer.len == 1 and status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len < 1: return - yankBuffer(status, area) +proc deleteBuffer(bufStatus: var BufferStatus, registers: var Registers, area: SelectArea) = + if bufStatus.buffer.len == 1 and bufStatus.buffer[bufStatus.currentLine].len < 1: return + yankBuffer(bufStatus, registers, area) + var currentLine = area.startLine for i in area.startLine .. area.endLine: - if area.startLine == area.endLine and status.bufStatus[status.currentBuffer].buffer[status.bufStatus[status.currentBuffer].currentLine].len > 1: - for j in area.startColumn .. area.endColumn: - status.bufStatus[status.currentBuffer].buffer[area.startLine].delete(area.startColumn) - elif i == area.startLine and area.startColumn > 0: - for j in area.startColumn .. status.bufStatus[status.currentBuffer].buffer[area.startLine].high: - status.bufStatus[status.currentBuffer].buffer[area.startLine].delete(area.startColumn) - elif i == area.endLine and area.endColumn < status.bufStatus[status.currentBuffer].buffer[area.startLine].high: - for j in 0 .. area.endColumn: - status.bufStatus[status.currentBuffer].buffer[area.startLine].delete(0) - elif status.bufStatus[status.currentBuffer].buffer.len == 1 and status.bufStatus[status.currentBuffer].buffer[0].len < 1: - break - else: - status.bufStatus[status.currentBuffer].buffer.delete(area.startLine, area.startLine + 1) + if area.startLine == area.endLine and 0 < bufStatus.buffer[currentLine].len: + for j in area.startColumn .. area.endColumn: bufStatus.buffer[currentLine].delete(area.startColumn) + elif i == area.startLine and 0 < area.startColumn: + for j in area.startColumn .. bufStatus.buffer[currentLine].high: bufStatus.buffer[currentLine].delete(area.startColumn) + inc(currentLine) + elif i == area.endLine and area.endColumn < bufStatus.buffer[currentLine].high: + for j in 0 .. area.endColumn: bufStatus.buffer[currentLine].delete(0) + else: bufStatus.buffer.delete(currentLine, currentLine + 1) + + if bufStatus.buffer.len < 1: bufStatus.buffer.add(ru"") + + if area.startLine > bufStatus.buffer.high: bufStatus.currentLine = bufStatus.buffer.high + else: bufStatus.currentLine = area.startLine + let column = if area.startColumn > 0: area.startColumn - 1 else: 0 + bufStatus.currentColumn = column + bufStatus.expandedColumn = column - inc(status.bufStatus[status.currentBuffer].countChange) - if area.startLine > status.bufStatus[status.currentBuffer].buffer.high: status.bufStatus[status.currentBuffer].currentLine = status.bufStatus[status.currentBuffer].buffer.high - else: status.bufStatus[status.currentBuffer].currentLine = area.startLine - status.bufStatus[status.currentBuffer].currentColumn = area.startColumn - status.bufStatus[status.currentBuffer].expandedColumn = area.startColumn + inc(bufStatus.countChange) proc addIndent(bufStatus: var BufferStatus, area: SelectArea, tabStop: int) = bufStatus.currentLine = area.startLine @@ -116,8 +115,8 @@ proc deleteIndent(bufStatus: var BufferStatus, area: SelectArea, tabStop: int) = proc visualCommand(status: var EditorStatus, area: var SelectArea, key: Rune) = area.swapSlectArea - if key == ord('y') or isDcKey(key): yankBuffer(status, area) - elif key == ord('x') or key == ord('d'): deleteBuffer(status, area) + if key == ord('y') or isDcKey(key): yankBuffer(status.bufStatus[status.currentBuffer], status.registers, area) + elif key == ord('x') or key == ord('d'): deleteBuffer(status.bufStatus[status.currentBuffer], status.registers, area) elif key == ord('>'): addIndent(status.bufStatus[status.currentBuffer], area, status.settings.tabStop) elif key == ord('<'): deleteIndent(status.bufStatus[status.currentBuffer], area, status.settings.tabStop) else: discard