-- Starting settings supplied with Lx Alpha builds
-- Updates may replace this file, so put shared choices in 'global.lua'

local keymap = require("core.keymap")
local config = require("core.config")
local style = require("core.style")

-- Debug
config.debug_auto_run_tests = false
config.debug_keymap = false
config.debug_keymap_strokes = { "ctrl+return" }
config.debug_font_load = true
config.font_glyph_page_size = 64

-- Custom theme
require("styles.liqube")

-- Fallback codepage for legacy text files
config.fallback_codepage = "cp1252"

config.animate_page_scroll = true
config.animate_vertical_edge_scroll = false

-- Experimental
config.auto_surround = true
config.format_shortcuts = true

config.syntax_line_backgrounds = true

config.fps_overlay.enabled = false

config.indent_size = 4
config.fps = 144
config.vsync = false
config.minimap_enabled = true
config.line_limit = 120
config.rulers = { config.line_limit }

config.binary_viewer_show_ruler = false

config.new_doc_auto_create_on_startup = true

-- Scroll wheel by line count instead of pixels
config.mouse_wheel_scroll_lines = 12

-- Set the Browser pane width and keep it closed by default
config.browser_width = 250 * SCALE

-- Keep browser hidden when Lx starts
config.browser_startup_visible = false

-- Show EOL markers (trailing whitespace only) by default
config.highlight_eol = "trailing"

-- Comments plugin line style
config.comments_place_after_indent = false -- true: after indent, false: beginning of line
config.comments_block_pad_inline = true -- true: /* text */, false: /*text*/
config.comments_keep_selection = true -- true: keep selection, false: clear selection

-- Highlight current word matches when no selection
config.highlight_current_word = false

-- Highlight matches of the current selection
config.highlight_selection_matches = true

-- Draw boxes around selection match candidates
config.highlight_selection_boxes = false

-- Alpha shortcuts grouped by the surfaces where their commands can run
keymap.bind({
	global = {
--		["f1"] = "browser:toggle",
		-- Toggle a document first and keep repeat-last-command as the non-document fallback
		["f9"] = { "doc:toggle-edit", "core:repeat-last-command" },
		["ctrl+shift+alt+o"] = "core:edit-user-settings",

		-- Escape closes panels/selection/doc before quitting
		["escape"] = "core:escape2",
		--	["escape"] = "core:escape",
		--	["escape"] = "root:close",

		-- Split view shortcuts
		["ctrl+alt+shift+right"] = "workspace:split-right",
		["ctrl+alt+shift+down"] = "workspace:split-down",

		-- Close tabs on F4
		--	["f4"] = "root:close",

		-- Toggle browser
		--	["ctrl+f4"] = "browser:toggle",
	},
	doc_view = {
		-- Fastscroll on Ctrl+Wheel
		--	["ctrl+wheelup"] = "doc:fastscroll-up",
		--	["ctrl+wheeldown"] = "doc:fastscroll-down",
	},
	text_editor = {
		-- Search
		--	["f7"] = "find-replace:find",
		--	["ctrl+f7"] = "find-replace:replace",

		-- Go to line
		--	["alt+f8"] = "doc:go-to-line",

		-- Disable default move lines, set to autocomplete navigation
		--	["ctrl+up"] = "command:select-previous",
		--	["ctrl+down"] = "command:select-next",

		-- Disable default autocomplete navigation
		--	["up"] = {
		--		"command:select-previous",
		--		"doc:move-to-previous-line",
		--	},
		--	["down"] = {
		--		"command:select-next",
		--		"doc:move-to-next-line",
		--	},

		-- Autocomplete and outline navigation
		["alt+up"] = {
--			"autocomplete:previous",
			"doc:outline-previous",
		},
		["alt+down"] = {
--			"autocomplete:next",
			"doc:outline-next",
		},
		["alt+home"] = "doc:outline-first",
		["alt+end"] = "doc:outline-last",
		["alt+wheelup"] = "doc:outline-previous",
		["alt+wheeldown"] = "doc:outline-next",

		-- Trim lines
		["alt+delete"] = "lines:trim-trailing-whitespaces",

		-- JSON formatting
		["ctrl+alt+j"] = "tidyjson:format",
		["shift+ctrl+alt+j"] = "tidyjson:minimize",

		-- Comments
		["alt+c"] = "comment:toggle-smart",
		["ctrl+alt+c"] = "comment:toggle-block",
		["ctrl+shift+c"] = "comment:toggle-guard",

		-- Move lines
		["ctrl+shift+up"] = "doc:move-lines-up",
		["ctrl+shift+down"] = "doc:move-lines-down",

		-- Select next occurrence or the word at the cursor
--		["ctrl+shift+d"] = {
--			"find-replace:select-next",
--			"doc:select-word",
--		},

		["ctrl+alt+pageup"] = "doc:scroll-page-up",
		["ctrl+alt+pagedown"] = "doc:scroll-page-down",
	},
})

-- Exchange outline list dialog and select-next-occurrence shortcuts
--keymap.swap({
--	text_editor = {
--		["ctrl+d"] = "alt+d",
--	},
--})

-- Example: Duplicate redo on another shortcut
--keymap.copy({
--  text_editor = {
--    ["ctrl+shift+z"] = "ctrl+y",
--  }
--})
