~tim/termy

ad15eb05df67cfcc6b8ff3fae2e2cea98faea8f1 — Tim Morgan 2 years ago db9cba5
Add normal mode keys: C, cc, D, dd
1 files changed, 46 insertions(+), 0 deletions(-)

M js/bin/vi.js
M js/bin/vi.js => js/bin/vi.js +46 -0
@@ 22,6 22,7 @@ class Vi extends Program {
    this.lineNum = 0
    this.colNum = 0
    this.firstCharInWindow = 0
    this.normalCommand = ''
  }

  get width() {


@@ 346,6 347,48 @@ class Vi extends Program {
            this.redraw()
            this.move()
            break
          case 'C':
            this.data.remove(this.dataIndex, this.dataIndex + this.currentLineLength - this.colNum)
            this.calculateLineLengths()
            this.insertMode()
            this.redraw()
            break
          case 'c':
            if (this.normalCommand === '') {
              this.normalCommand = 'c'
            } else if (this.normalCommand === 'c') {
              this.normalCommand = ''
              match = this.currentLine.match(/^\s*/)
              this.data.remove(this.dataIndex - this.colNum + match[0].length, this.dataIndex - this.colNum + this.currentLineLength)
              this.calculateLineLengths()
              this.insertMode()
              this.colNum = match[0].length
              this.move()
              this.redraw()
            } else {
              this.normalCommand = ''
            }
            break
          case 'D':
            this.data.remove(this.dataIndex, this.dataIndex + this.currentLineLength - this.colNum)
            this.calculateLineLengths()
            this.fixColNum()
            this.redraw()
            break
          case 'd':
            if (this.normalCommand === '') {
              this.normalCommand = 'd'
            } else if (this.normalCommand === 'd') {
              this.normalCommand = ''
              this.data.remove(this.dataIndex - this.colNum, this.dataIndex - this.colNum + this.currentLineLength + 1)
              this.calculateLineLengths()
              this.fixColNum()
              this.move()
              this.redraw()
            } else {
              this.normalCommand = ''
            }
            break
          case 'w':
          case 'W':
            line = this.currentLine.substring(this.colNum)


@@ 385,6 428,9 @@ class Vi extends Program {
          case ':':
            this.commandMode()
            break
          case 'Escape':
            this.normalCommand = ''
            break
        }
        //this.message(this.dataIndex.toString() + '    ')
        break