Skip to content

Commit

Permalink
Merge pull request #790 from fox0430/hotfix
Browse files Browse the repository at this point in the history
v0.2.0.2
  • Loading branch information
fox0430 authored Jul 9, 2020
2 parents 4be05eb + 8e47cd4 commit a6c10ae
Show file tree
Hide file tree
Showing 5 changed files with 953 additions and 955 deletions.
2 changes: 1 addition & 1 deletion moe.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.0.1"
version = "0.2.0.2"
author = "fox0430"
description = "A command lined based text editor"
license = "GPLv3"
Expand Down
17 changes: 13 additions & 4 deletions src/moepkg/replacemode.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import terminal
import editorstatus, ui, unicodeext, movement, editor, bufferstatus
import editorstatus, ui, unicodeext, movement, editor, bufferstatus, gapbuffer

proc isReplaceMode(status: EditorStatus): bool =
let
Expand All @@ -13,6 +13,17 @@ proc replaceMode*(status: var EditorStatus) =
windowNode =
status.workSpace[status.currentWorkSpaceIndex].currentMainWindowNode

template replaceCurrentCharacter() =
let
workspaceIndex = status.currentWorkSpaceIndex
windowNode = status.workSpace[workSpaceIndex].currentMainWindowNode
buffer = status.bufStatus[currentBufferIndex].buffer

if windowNode.currentColumn < buffer[windowNode.currentLine].len:
status.bufStatus[currentBufferIndex].replaceCurrentCharacter(
status.workSpace[workspaceIndex].currentMainWindowNode,
status.settings.autoIndent, status.settings.autoDeleteParen, key)

while status.isReplaceMode:
let currentBufferIndex = status.bufferIndexInCurrentWindow

Expand Down Expand Up @@ -43,9 +54,7 @@ proc replaceMode*(status: var EditorStatus) =
status.bufStatus[currentBufferIndex].keyDown(windowNode)

else:
status.bufStatus[currentBufferIndex].replaceCurrentCharacter(
status.workSpace[status.currentWorkSpaceIndex].currentMainWindowNode,
status.settings.autoIndent, status.settings.autoDeleteParen, key)
replaceCurrentCharacter()

status.bufStatus[currentBufferIndex].keyRight(windowNode)
bufferChanged = true
61 changes: 47 additions & 14 deletions tests/teditor.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import unittest
include moepkg/[editor, editorstatus]

suite "editor.nim":
suite "Editor: Auto indent":
test "Auto indent in current Line":
var status = initEditorStatus()
status.addNewBuffer("")

status.bufStatus[0].buffer = initGapBuffer(@[ru" a", ru"b"])

status.workSpace[0].currentMainWindowNode.currentLine = 1

status.bufStatus[0].autoIndentCurrentLine(
status.workspace[0].currentMainWindowNode
)
Expand All @@ -20,11 +20,11 @@ suite "editor.nim":
test "Auto indent in current Line 2":
var status = initEditorStatus()
status.addNewBuffer("")

status.bufStatus[0].buffer = initGapBuffer(@[ru"a", ru"b"])

status.workSpace[0].currentMainWindowNode.currentLine = 1

status.bufStatus[0].autoIndentCurrentLine(
status.workspace[0].currentMainWindowNode
)
Expand All @@ -35,11 +35,11 @@ suite "editor.nim":
test "Auto indent in current Line 3":
var status = initEditorStatus()
status.addNewBuffer("")

status.bufStatus[0].buffer = initGapBuffer(@[ru"a", ru" b"])

status.workSpace[0].currentMainWindowNode.currentLine = 1

status.bufStatus[0].autoIndentCurrentLine(
status.workspace[0].currentMainWindowNode
)
Expand All @@ -50,26 +50,59 @@ suite "editor.nim":
test "Auto indent in current Line 4":
var status = initEditorStatus()
status.addNewBuffer("")

status.bufStatus[0].buffer = initGapBuffer(@[ru""])

status.bufStatus[0].autoIndentCurrentLine(
status.workspace[0].currentMainWindowNode
)

check(status.bufStatus[0].buffer[0] == ru"")

test "Delete trailing spaces":
suite "Editor: Delete trailing spaces":
test "Delete trailing spaces 1":
var status = initEditorStatus()
status.addNewBuffer("")

status.bufStatus[0].buffer = initGapBuffer(@[ru"abc",
ru"d ",
ru"efg"])

status.bufStatus[0].buffer = initGapBuffer(@[ru"abc", ru"d ", ru"efg"])

status.bufStatus[0].deleteTrailingSpaces

check status.bufStatus[0].buffer.len == 3
check status.bufStatus[0].buffer[0] == ru"abc"
check status.bufStatus[0].buffer[1] == ru"d"
check status.bufStatus[0].buffer[2] == ru"efg"

suite "Editor: Send to clipboad":
test "Send string to clipboard 1":
const str = ru"Clipboard test"
const registers = editorstatus.Registers(yankedLines: @[], yankedStr: str)

const platform = editorstatus.Platform.linux
sendToClipboad(registers, platform)

let (output, exitCode) = execCmdEx("xclip -o")

check exitCode == 0 and output[0 .. output.high - 1] == "Clipboard test"

test "Send string to clipboard 2":
const str = ru"`````"
const registers = editorstatus.Registers(yankedLines: @[], yankedStr: str)

const platform = editorstatus.Platform.linux
registers.sendToClipboad(platform)

let (output, exitCode) = execCmdEx("xclip -o")

check exitCode == 0 and output[0 .. output.high - 1] == "`````"

test "Send string to clipboard 3":
const str = ru"$Clipboard test"
const registers = editorstatus.Registers(yankedLines: @[], yankedStr: str)

const platform = editorstatus.Platform.linux
registers.sendToClipboad(platform)

let (output, exitCode) = execCmdEx("xclip -o")

check exitCode == 0 and output[0 .. output.high - 1] == "$Clipboard test"
Loading

0 comments on commit a6c10ae

Please sign in to comment.