Skip to content

Commit

Permalink
Merge pull request #134 from fox0430/fix#133
Browse files Browse the repository at this point in the history
Ex mode: Bugfix #133
  • Loading branch information
fox0430 authored Jan 23, 2019
2 parents 4710702 + 652ef66 commit 6f5d7fe
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/moepkg/exmode.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sequtils, strutils, os, terminal, strformat, deques
import editorstatus, ui, normalmode, gapbuffer, fileutils, editorview, unicodeext, independentutils, searchmode
import editorstatus, ui, normalmode, gapbuffer, fileutils, editorview, unicodeext, independentutils, searchmode, highlight


type
Expand Down Expand Up @@ -91,23 +91,29 @@ proc editCommand(status: var EditorStatus, filename: seq[Rune]) =
writeNoWriteError(status.commandWindow)
status.changeMode(Mode.normal)
return
if existsFile($filename):
let textAndEncoding = openFile(filename)
status = initEditorStatus()
status.filename = filename
status.buffer = textAndEncoding.text.toGapBuffer
status.settings.characterEncoding = textAndEncoding.encoding
let useStatusBar = if status.settings.statusBar.useBar: 1 else: 0
status.view = initEditorView(status.buffer, terminalHeight() - useStatusBar - 1, terminalWidth()-numberOfDigits(status.buffer.len)-2)
elif existsDir($filename):

if existsDir($filename):
setCurrentDir($filename)
status.changeMode(Mode.filer)
else:
status = initEditorStatus()
status.filename = filename
status.buffer = newFile()
status.language = detectLanguage($filename)
if existsFile($status.filename):
try:
let textAndEncoding = openFile(status.filename)
status.buffer = textAndEncoding.text.toGapBuffer
status.settings.characterEncoding = textAndEncoding.encoding
except IOError:
#writeFileOpenErrorMessage(status.commandWindow, status.filename)
status.buffer = newFile()
else:
status.buffer = newFile()

let numberOfDigitsLen = if status.settings.lineNumber: numberOfDigits(status.buffer.len) - 2 else: 0
let useStatusBar = if status.settings.statusBar.useBar: 1 else: 0
status.view = initEditorView(status.buffer, terminalHeight() - useStatusBar - 1, terminalWidth()-numberOfDigits(status.buffer.len)-2)
status.highlight = initHighlight($status.buffer, status.language)
status.view = initEditorView(status.buffer, terminalHeight() - useStatusBar - 1, terminalWidth() - numberOfDigitsLen)

proc writeCommand(status: var EditorStatus, filename: seq[Rune]) =
if filename.len == 0:
Expand Down

0 comments on commit 6f5d7fe

Please sign in to comment.