package core // RegisterType: Indicates how the register content should be interpreted when // pasting. Charwise treats content as continuous text, linewise operates on // complete lines, and blockwise represents rectangular selections. type RegisterType int const ( CharwiseRegister RegisterType = iota LinewiseRegister BlockwiseRegister ) func (r RegisterType) ToString() string { switch r { case CharwiseRegister: return "c" case LinewiseRegister: return "l" case BlockwiseRegister: return "b" } return "-" } // Register: Stores yanked or deleted text with metadata about how it should be // pasted. The Type determines paste behavior and Content holds the text lines. type Register struct { Type RegisterType Content []string } // DefaultRegisters: Creates and initializes the complete set of vim-style // registers. Returns a map containing special registers (", *, _, etc.), // named registers (a-z), and numbered registers (0-9). func DefaultRegisters() map[rune]Register { reg := make(map[rune]Register) addSpecialRegisters(reg) addNamedRegisters(reg) addNumberedRegisters(reg) return reg } // addNamedRegisters: Initializes the 26 named registers (a-z) used for explicit // yank/delete operations. Users can target these with commands like "ayy or "ap. func addNamedRegisters(reg map[rune]Register) { name := 'a' for name <= 'z' { reg[name] = emptyRegister() name++ } } // addNumberedRegisters: Initializes the numbered registers (0-9) which form the // delete history. Register 0 holds the most recent yank, and 1-9 hold previous // deletes in chronological order. func addNumberedRegisters(reg map[rune]Register) { name := '0' for name <= '9' { reg[name] = emptyRegister() name++ } } // addSpecialRegisters: Initializes special-purpose registers with specific // behaviors. Includes the unnamed register ("), black hole (_), clipboard (*), // last insert (.), current filename (%), last command (:), and alternate file (#). func addSpecialRegisters(reg map[rune]Register) { // Unnamed (default) reg['"'] = emptyRegister() // Black hole (readonly) reg['_'] = emptyRegister() // System clipboard reg['*'] = emptyRegister() // Small delete? Expression? // VIM: Last inserted text (readonly) // GIM: Content stored for the '.' operator (for debugging) reg['.'] = emptyRegister() // Current file name (readonly) reg['%'] = emptyRegister() // Last executed command (readonly) reg[':'] = emptyRegister() // Alternate (previous) file (readonly) reg['#'] = emptyRegister() } // emptyRegister: Creates a new register initialized with charwise type and empty // content. Used as the default state for all registers during initialization. func emptyRegister() Register { return Register{ Type: CharwiseRegister, Content: []string{}, } }