mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +00:00
trim text selection range when appropriate; fix #22
This commit is contained in:
@@ -8,6 +8,13 @@ local ROOT = (...):gsub('[^.]*.[^.]*$', '')
|
|||||||
local utf8 = require(ROOT .. 'utf8')
|
local utf8 = require(ROOT .. 'utf8')
|
||||||
local Backend = require(ROOT .. 'backend')
|
local Backend = require(ROOT .. 'backend')
|
||||||
|
|
||||||
|
-- make sure selection range doesn't extend past EOT
|
||||||
|
local function trimRange (self)
|
||||||
|
local max = #self.value
|
||||||
|
if self.startIndex > max then self.startIndex = max end
|
||||||
|
if self.endIndex > max then self.endIndex = max end
|
||||||
|
end
|
||||||
|
|
||||||
local function updateHighlight (self)
|
local function updateHighlight (self)
|
||||||
local value = self.value
|
local value = self.value
|
||||||
local font = self:getFont()
|
local font = self:getFont()
|
||||||
@@ -34,6 +41,7 @@ end
|
|||||||
local function selectRange (self, startIndex, endIndex)
|
local function selectRange (self, startIndex, endIndex)
|
||||||
if startIndex then self.startIndex = startIndex end
|
if startIndex then self.startIndex = startIndex end
|
||||||
if endIndex then self.endIndex = endIndex end
|
if endIndex then self.endIndex = endIndex end
|
||||||
|
trimRange(self)
|
||||||
|
|
||||||
scrollToCaret(self)
|
scrollToCaret(self)
|
||||||
end
|
end
|
||||||
@@ -72,6 +80,7 @@ end
|
|||||||
|
|
||||||
-- move the caret one character to the left
|
-- move the caret one character to the left
|
||||||
local function moveCaretLeft (self, alterRange)
|
local function moveCaretLeft (self, alterRange)
|
||||||
|
trimRange(self)
|
||||||
local text, endIndex = self.value, self.endIndex
|
local text, endIndex = self.value, self.endIndex
|
||||||
|
|
||||||
-- clamp caret to beginning
|
-- clamp caret to beginning
|
||||||
@@ -84,6 +93,7 @@ end
|
|||||||
|
|
||||||
-- move the caret one character to the right
|
-- move the caret one character to the right
|
||||||
local function moveCaretRight (self, alterRange)
|
local function moveCaretRight (self, alterRange)
|
||||||
|
trimRange(self)
|
||||||
local text, endIndex = self.value, self.endIndex
|
local text, endIndex = self.value, self.endIndex
|
||||||
|
|
||||||
-- clamp caret to end
|
-- clamp caret to end
|
||||||
@@ -95,6 +105,7 @@ local function moveCaretRight (self, alterRange)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getRange (self)
|
local function getRange (self)
|
||||||
|
trimRange(self)
|
||||||
if self.startIndex <= self.endIndex then
|
if self.startIndex <= self.endIndex then
|
||||||
return self.startIndex, self.endIndex
|
return self.startIndex, self.endIndex
|
||||||
end
|
end
|
||||||
@@ -103,6 +114,7 @@ local function getRange (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function deleteRange (self)
|
local function deleteRange (self)
|
||||||
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
|
|
||||||
@@ -117,6 +129,7 @@ local function deleteRange (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function deleteCharacterLeft (self)
|
local function deleteCharacterLeft (self)
|
||||||
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
|
|
||||||
@@ -134,6 +147,7 @@ local function deleteCharacterLeft (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function copyRangeToClipboard (self)
|
local function copyRangeToClipboard (self)
|
||||||
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
if last >= first + 1 then
|
if last >= first + 1 then
|
||||||
@@ -142,6 +156,7 @@ local function copyRangeToClipboard (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function pasteFromClipboard (self)
|
local function pasteFromClipboard (self)
|
||||||
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
local pasted = Backend.getClipboardText() or ''
|
local pasted = Backend.getClipboardText() or ''
|
||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
@@ -152,6 +167,7 @@ local function pasteFromClipboard (self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function insertText (self, newText)
|
local function insertText (self, newText)
|
||||||
|
trimRange(self)
|
||||||
local text = self.value
|
local text = self.value
|
||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
local left = text:sub(1, first) .. newText
|
local left = text:sub(1, first) .. newText
|
||||||
|
|||||||
Reference in New Issue
Block a user