diff --git a/.DS_Store b/.DS_Store index 74d730cd..bf3e1cda 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Applications.txt b/Applications.txt index 23ebcbc4..c0e00c07 100644 --- a/Applications.txt +++ b/Applications.txt @@ -300,7 +300,7 @@ name="lib/GUI.lua", url="IgorTimofeev/OpenComputers/master/lib/GUI.lua", type="Library", - version=1.39, + version=1.40, }, { name="lib/windows.lua", @@ -360,7 +360,7 @@ name="lib/syntax.lua", url="IgorTimofeev/OpenComputers/master/lib/syntax.lua", type="Library", - version=1.09, + version=1.10, }, { name="lib/palette.lua", @@ -517,7 +517,7 @@ icon="IgorTimofeev/OpenComputers/master/Applications/MineCodeIDE/Icon.pic", createShortcut="dock", forceDownload=true, - version=1.48, + version=1.49, resources={ { name="Localization/Russian.lang", diff --git a/Applications/.DS_Store b/Applications/.DS_Store index e949c7ba..cb90986e 100644 Binary files a/Applications/.DS_Store and b/Applications/.DS_Store differ diff --git a/Applications/MineCodeIDE/Localization/English.lang b/Applications/MineCodeIDE/Localization/English.lang index 333a702a..55b59e39 100755 --- a/Applications/MineCodeIDE/Localization/English.lang +++ b/Applications/MineCodeIDE/Localization/English.lang @@ -1,4 +1,6 @@ { + enableAutoBrackets = "Enable autobrackets", + disableAutoBrackets = "Disable autobrackets", url = "http://example.com/something.lua", getFromWeb = "Download from URL", debugging = "Debugger on line ", diff --git a/Applications/MineCodeIDE/Localization/Russian.lang b/Applications/MineCodeIDE/Localization/Russian.lang index 2291b016..b27c99a4 100755 --- a/Applications/MineCodeIDE/Localization/Russian.lang +++ b/Applications/MineCodeIDE/Localization/Russian.lang @@ -1,4 +1,6 @@ { + enableAutoBrackets = "Включить авто-скобки", + disableAutoBrackets = "Отключить авто-скобки", url = "http://example.com/something.lua", getFromWeb = "Загрузить по URL", debugging = "Отладчик на строке ", diff --git a/Applications/MineCodeIDE/MineCodeIDE.lua b/Applications/MineCodeIDE/MineCodeIDE.lua index b7c9a928..48b4d5db 100755 --- a/Applications/MineCodeIDE/MineCodeIDE.lua +++ b/Applications/MineCodeIDE/MineCodeIDE.lua @@ -57,7 +57,7 @@ local config = { cursorBlinkDelay = 0.5, doubleClickDelay = 0.4, screenScale = 1, - enableAutoBrackets = true + enableAutoBrackets = true, } local colors = { @@ -95,9 +95,20 @@ local colors = { } local possibleBrackets = { - ["{"] = "}", - ["["] = "]", - ["("] = ")", + openers = { + ["{"] = "}", + ["["] = "]", + ["("] = ")", + ["\""] = "\"", + ["\'"] = "\'" + }, + closers = { + ["}"] = "{", + ["]"] = "[", + [")"] = "(", + ["\""] = "\"", + ["\'"] = "\'" + } } local cursor = { @@ -734,17 +745,62 @@ local function paste(pasteLines) end end -local function pasteAutoBrackets(firstSymbol, secondSymbol) - if config.enableAutoBrackets then - paste({firstSymbol .. secondSymbol}) - setCursorPosition(cursor.position.symbol - 1, cursor.position.line) - else - paste({firstSymbol}) +local function pasteRegularChar(unicodeByte, char) + if not keyboard.isControl(unicodeByte) then + deleteSelectedData() + paste({char}) end end -local function backspaceAutoBrackets() - if config.enableAutoBrackets and unicode.sub(mainWindow.codeView.lines[cursor.position.line], cursor.position.symbol - 1, cursor.position.symbol - 1):match("[%{%[%(]") then +local function pasteAutoBrackets(unicodeByte) + local char = unicode.char(unicodeByte) + local currentSymbol = unicode.sub(mainWindow.codeView.lines[cursor.position.line], cursor.position.symbol, cursor.position.symbol) + + -- Если у нас вообще врублен режим автоскобок, то чекаем их + if config.enableAutoBrackets then + -- Ситуация, когда курсор находится на закрывающей скобке, и нехуй ее еще раз вставлять + if possibleBrackets.closers[char] and currentSymbol == char then + deleteSelectedData() + setCursorPosition(cursor.position.symbol + 1, cursor.position.line) + -- Если нажата открывающая скобка + elseif possibleBrackets.openers[char] then + -- А вот тут мы берем в скобочки уже выделенный текст + if mainWindow.codeView.selections[1] then + local firstPart = unicode.sub(mainWindow.codeView.lines[mainWindow.codeView.selections[1].from.line], 1, mainWindow.codeView.selections[1].from.symbol - 1) + local secondPart = unicode.sub(mainWindow.codeView.lines[mainWindow.codeView.selections[1].from.line], mainWindow.codeView.selections[1].from.symbol, -1) + mainWindow.codeView.lines[mainWindow.codeView.selections[1].from.line] = firstPart .. char .. secondPart + mainWindow.codeView.selections[1].from.symbol = mainWindow.codeView.selections[1].from.symbol + 1 + + if mainWindow.codeView.selections[1].to.line == mainWindow.codeView.selections[1].from.line then + mainWindow.codeView.selections[1].to.symbol = mainWindow.codeView.selections[1].to.symbol + 1 + end + + firstPart = unicode.sub(mainWindow.codeView.lines[mainWindow.codeView.selections[1].to.line], 1, mainWindow.codeView.selections[1].to.symbol) + secondPart = unicode.sub(mainWindow.codeView.lines[mainWindow.codeView.selections[1].to.line], mainWindow.codeView.selections[1].to.symbol + 1, -1) + mainWindow.codeView.lines[mainWindow.codeView.selections[1].to.line] = firstPart .. possibleBrackets.openers[char] .. secondPart + -- А тут мы делаем двойную автоскобку, если можем + elseif possibleBrackets.openers[char] and not currentSymbol:match("[%a%d%_]") then + paste({char .. possibleBrackets.openers[char]}) + setCursorPosition(cursor.position.symbol - 1, cursor.position.line) + cursor.blinkState = false + -- Ну, и если нет ни выделений, ни можем ебануть автоскобочку по регулярке + else + pasteRegularChar(unicodeByte, char) + end + -- Если мы вообще на скобку не нажимали + else + pasteRegularChar(unicodeByte, char) + end + -- Если оффнуты афтоскобки + else + pasteRegularChar(unicodeByte, char) + end +end + +local function backspaceAutoBrackets() + local previousSymbol = unicode.sub(mainWindow.codeView.lines[cursor.position.line], cursor.position.symbol - 1, cursor.position.symbol - 1) + local currentSymbol = unicode.sub(mainWindow.codeView.lines[cursor.position.line], cursor.position.symbol, cursor.position.symbol) + if config.enableAutoBrackets and possibleBrackets.openers[previousSymbol] and possibleBrackets.openers[previousSymbol] == currentSymbol then deleteSpecifiedData(cursor.position.symbol, cursor.position.line, cursor.position.symbol, cursor.position.line) end end @@ -1043,7 +1099,7 @@ local function createWindow() deleteLine(cursor.position.line) end menu:addSeparator() - menu:addItem(localization.selectWord, false, "^\\").onTouch = function() + menu:addItem(localization.selectWord).onTouch = function() selectWord() end menu:addItem(localization.selectAll, false, "^A").onTouch = function() @@ -1104,11 +1160,21 @@ local function createWindow() end if mainWindow.topToolBar.isHidden then - menu:addSeparator() menu:addItem(localization.toggleTopToolBar).onTouch = function() toggleTopToolBar() end end + if config.enableAutoBrackets then + menu:addItem(localization.disableAutoBrackets, false, "^]").onTouch = function() + config.enableAutoBrackets = false + saveConfig() + end + else + menu:addItem(localization.enableAutoBrackets, false, "^]").onTouch = function() + config.enableAutoBrackets = true + saveConfig() + end + end menu:addSeparator() menu:addItem(localization.scalePlus, false, "^+").onTouch = function() @@ -1236,6 +1302,9 @@ local function createWindow() paste(clipboard) end menu:addSeparator() + menu:addItem(localization.selectWord).onTouch = function() + selectWord() + end menu:addItem(localization.selectAll, false, "^A").onTouch = function() selectAll() end @@ -1269,12 +1338,13 @@ local function createWindow() -- Ctrl or CMD if keyboard.isKeyDown(29) or keyboard.isKeyDown(219) then - -- Backslash - if eventData[4] == 43 then - selectWord() -- Slash - elseif eventData[4] == 53 then + if eventData[4] == 53 then toggleComment() + -- ] + elseif eventData[4] == 27 then + config.enableAutoBrackets = not config.enableAutoBrackets + saveConfig() -- A elseif eventData[4] == 30 then selectAll() @@ -1367,14 +1437,7 @@ local function createWindow() elseif eventData[4] == 211 then delete() else - local char = unicode.char(eventData[3]) - if possibleBrackets[char] then - pasteAutoBrackets(char, possibleBrackets[char]) - cursor.blinkState = false - elseif not keyboard.isControl(eventData[3]) then - deleteSelectedData() - paste({char}) - end + pasteAutoBrackets(eventData[3]) end elseif eventData[1] == "clipboard" then paste(splitStringIntoLines(eventData[3])) diff --git a/lib/GUI.lua b/lib/GUI.lua index 321890dd..5ca1503d 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -1525,7 +1525,7 @@ local function codeViewDraw(codeView) codeView.lineNumbersWidth = unicode.len(tostring(toLine)) + 2 codeView.codeAreaPosition = codeView.x + codeView.lineNumbersWidth codeView.codeAreaWidth = codeView.width - codeView.lineNumbersWidth - buffer.square(codeView.x, codeView.y, codeView.lineNumbersWidth, codeView.height, syntax.colorScheme.lineNumbers, syntax.colorScheme.lineNumbersText, " ") + buffer.square(codeView.x, codeView.y, codeView.lineNumbersWidth, codeView.height, syntax.colorScheme.lineNumbersBackground, syntax.colorScheme.lineNumbersText, " ") buffer.square(codeView.codeAreaPosition, codeView.y, codeView.codeAreaWidth, codeView.height, syntax.colorScheme.background, syntax.colorScheme.text, " ") -- Line numbers texts diff --git a/lib/syntax.lua b/lib/syntax.lua index c300e524..c6af4f25 100755 --- a/lib/syntax.lua +++ b/lib/syntax.lua @@ -20,7 +20,7 @@ syntax.colorScheme = { numbers = 0x66DBFF, functions = 0xffcc66, compares = 0xffff98, - lineNumbers = 0x2D2D2D, + lineNumbersBackground = 0x2D2D2D, lineNumbersText = 0xCCCCCC, scrollBarBackground = 0x444444, scrollBarForeground = 0x33B6FF,