#include <ncurses.h>

#include "../../../src/contents.hh"
#include "../../../src/key_aliases.hh"
#include "../../vick-move/src/move.hh"

void enter_insert_mode(contents& contents, boost::optional<int>) {
    char ch;
    contents.is_inserting = true;
    while((ch = getch()) != _escape) {
        contents.cont[contents.y].insert(contents.x, 1, ch);
        mvf(contents);
        if(get_contents().refresh) {
            print_contents(get_contents());
        }
    }
    contents.is_inserting = false;
}

void enter_replace_mode(contents& contents, boost::optional<int>) {
    char ch;
    contents.is_inserting = true;
    while((ch = getch()) != _escape) {
        if(contents.x >= contents.cont[contents.y].size()) {
            contents.cont[contents.y].push_back(ch);
        } else {
            contents.cont[contents.y][contents.x] = ch;
        }
        if(get_contents().refresh) {
            print_contents(get_contents());
        }
    }
    contents.is_inserting = false;
}

#include <ncurses.h>

#include "../../../src/contents.hh"
#include "../../../src/key_aliases.hh"
#include "../../vick-move/src/move.hh"

void enter_insert_mode(contents& contents, boost::optional<int>) {
    char ch;
    contents.is_inserting = true;
    while((ch = getch()) != _escape) {
        contents.cont[contents.y].insert(contents.x, 1, ch);
        mvf(contents);
        if(get_contents().refresh) {
            print_contents(get_contents());
        }
    }
    contents.is_inserting = false;
}

void enter_replace_mode(contents& contents, boost::optional<int>) {
    char ch;
    contents.is_inserting = true;
    while((ch = getch()) != _escape) {
        if(contents.x >= contents.cont[contents.y].size()) {
            contents.cont[contents.y].push_back(ch);
            contents.x = contents.cont[contents.y].size();
        } else {
            contents.cont[contents.y][contents.x] = ch;
            contents.x++;
        }
        if(get_contents().refresh) {
            print_contents(get_contents());
        }
    }
    contents.is_inserting = false;
}

Fix ``enter_replace_mode`` so that it works properly
Fix ``enter_replace_mode`` so that it works properly
