-- lx-bundle:true

--- Text editing surface for document-backed text panes
-- @module core.text.editor

local config = require("core.config")
local TextSurface = require("core.text.surface")

local TextEditor = TextSurface:extend()

--- Return key binding contexts for the text editor surface
-- The editor keeps its own context ahead of the shared document scope
-- @return table contexts ordered from most specific to broadest
function TextEditor:get_keymap_contexts()
	return { "text_editor", "doc_view", "global" }
end

--- Build one editable text surface
-- @param doc table document model
-- @param opts table|nil view construction options
function TextEditor:new(doc, opts)
	TextEditor.super.new(self, doc)
	self.gutter_visible = config.text_editor_gutter ~= false
	self.line_numbers_visible = config.text_editor_line_numbers ~= false
	if type(opts) == "table" and opts.word_wrap ~= nil then
		self.wrap_enabled = opts.word_wrap == true
	else
		self.wrap_enabled = config.text_editor_word_wrap == true
	end
	self:invalidate_wrap_layout(1, #self.doc.lines, "editor_new")
end

return TextEditor
