<commit_before>package kbmap

import (
	//"fmt"
	"github.com/driusan/de/actions"
	"github.com/driusan/de/demodel"
	"github.com/driusan/de/position"
	"golang.org/x/mobile/event/key"
)

var Repeat uint

func normalMap(e key.Event, buff *demodel.CharBuffer, v demodel.Viewport) (demodel.Map, demodel.ScrollDirection, error) {
	// things only happen on key press in normal mode, if it's a release
	// or a repeat, ignore it. It's not an error
	if e.Direction != key.DirPress {
		return NormalMode, demodel.DirectionNone, nil
	}
	if buff == nil {
		return NormalMode, demodel.DirectionNone, Invalid
	}
	switch e.Code {
	case key.CodeEscape:
		actions.Do("SaveOrExit", buff, v)
		return NormalMode, demodel.DirectionUp, nil
	case key.CodeDeleteBackspace:
		if e.Direction == key.DirPress {
			actions.DeleteCursor(position.DotStart, position.DotEnd, buff)
		}
		// There's a potential that we're pressing backspace at the start of the
		// screen and may need to scroll up
		return NormalMode, demodel.DirectionUp, nil
	case key.CodeI:
		return InsertMode, demodel.DirectionNone, nil
	case key.CodeA:
		if buff.Buffer[buff.Dot.End] == '\n' {
			// vi doesn't actually let you navigate your cursor *on top*<commit_msg>Fixed index out of range panic when appending after end of buffer.<commit_after>package kbmap

import (
	//"fmt"
	"github.com/driusan/de/actions"
	"github.com/driusan/de/demodel"
	"github.com/driusan/de/position"
	"golang.org/x/mobile/event/key"
)

var Repeat uint

func normalMap(e key.Event, buff *demodel.CharBuffer, v demodel.Viewport) (demodel.Map, demodel.ScrollDirection, error) {
	// things only happen on key press in normal mode, if it's a release
	// or a repeat, ignore it. It's not an error
	if e.Direction != key.DirPress {
		return NormalMode, demodel.DirectionNone, nil
	}
	if buff == nil {
		return NormalMode, demodel.DirectionNone, Invalid
	}
	switch e.Code {
	case key.CodeEscape:
		actions.Do("SaveOrExit", buff, v)
		return NormalMode, demodel.DirectionUp, nil
	case key.CodeDeleteBackspace:
		if e.Direction == key.DirPress {
			actions.DeleteCursor(position.DotStart, position.DotEnd, buff)
		}
		// There's a potential that we're pressing backspace at the start of the
		// screen and may need to scroll up
		return NormalMode, demodel.DirectionUp, nil
	case key.CodeI:
		return InsertMode, demodel.DirectionNone, nil
	case key.CodeA:
		if buff.Dot.End >= uint(len(buff.Buffer)) {
			return InsertMode, demodel.DirectionDown, nil
		}
		if buff.Buffer[buff.Dot.End] == '\n' {
			// vi doesn't actually let you navigate your cursor *on top*
{'fraction_non_alphanumeric': 0.11072261072261072, 'fraction_numerical': 0.0, 'mean_word_length': 3.951923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6569741', 'n_tokens_mistral': 921, 'n_tokens_neox': 862, 'n_words': 257}