Improve multiline text selection, closes #507
This commit is contained in:
parent
6893a5e98a
commit
0c1540e531
|
@ -113,13 +113,7 @@ function init()
|
||||||
local tab = consoleTabBar:getCurrentTab()
|
local tab = consoleTabBar:getCurrentTab()
|
||||||
if not tab then return false end
|
if not tab then return false end
|
||||||
|
|
||||||
local consoleBuffer = tab.tabPanel:getChildById('consoleBuffer')
|
g_window.setClipboardText(selectioText)
|
||||||
if not consoleBuffer then return false end
|
|
||||||
|
|
||||||
local consoleLabel = consoleBuffer:getFocusedChild()
|
|
||||||
if not consoleLabel then return false end
|
|
||||||
|
|
||||||
g_window.setClipboardText(getSelection(consoleLabel))
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,31 +141,12 @@ function init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function getSelection(widget)
|
function clearSelection(consoleBuffer)
|
||||||
if not widget.selection then
|
for _,label in pairs(consoleBuffer:getChildren()) do
|
||||||
return widget:getSelection()
|
|
||||||
end
|
|
||||||
|
|
||||||
local text = {}
|
|
||||||
for selectionChild = widget.selection.first, widget.selection.last do
|
|
||||||
local label = widget:getParent():getChildByIndex(selectionChild)
|
|
||||||
table.insert(text, label:getSelection())
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(text, '\r\n')
|
|
||||||
end
|
|
||||||
|
|
||||||
function invalidateSelection(widget)
|
|
||||||
local parent = widget:getParent()
|
|
||||||
if widget.selection then
|
|
||||||
for selectionChild = widget.selection.first, widget.selection.last do
|
|
||||||
local label = parent:getChildByIndex(selectionChild)
|
|
||||||
if label ~= widget then
|
|
||||||
label:clearSelection()
|
label:clearSelection()
|
||||||
end
|
end
|
||||||
end
|
consoleBuffer.selectionText = nil
|
||||||
widget.selection = nil
|
consoleBuffer.selection = nil
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function toggleChat()
|
function toggleChat()
|
||||||
|
@ -604,31 +579,59 @@ function addTabText(text, speaktype, tab, creatureName)
|
||||||
end
|
end
|
||||||
|
|
||||||
label.name = creatureName
|
label.name = creatureName
|
||||||
|
consoleBuffer.onMouseRelease = function(self, mousePos, mouseButton)
|
||||||
|
processMessageMenu(mousePos, mouseButton, nil, nil, nil, tab)
|
||||||
|
end
|
||||||
label.onMouseRelease = function(self, mousePos, mouseButton)
|
label.onMouseRelease = function(self, mousePos, mouseButton)
|
||||||
-- TODO: regain lost selection
|
|
||||||
processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab)
|
processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab)
|
||||||
end
|
end
|
||||||
label.onFocusChange = function(self, focused, reason)
|
|
||||||
-- TODO: we are losing focus on context menu and therefore the selection
|
|
||||||
if not focused then invalidateSelection(self) end
|
|
||||||
end
|
|
||||||
label.onMousePress = function(self, mousePos, button)
|
label.onMousePress = function(self, mousePos, button)
|
||||||
if button == MouseLeftButton then invalidateSelection(self) end
|
if button == MouseLeftButton then clearSelection(consoleBuffer) end
|
||||||
end
|
end
|
||||||
label.onMouseMove = function(self, mousePos, mouseMoved)
|
label.onDragEnter = function(self, mousePos)
|
||||||
if self:isPressed() then
|
clearSelection(consoleBuffer)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
label.onDragLeave = function(self, droppedWidget, mousePos)
|
||||||
|
local text = {}
|
||||||
|
for selectionChild = consoleBuffer.selection.first, consoleBuffer.selection.last do
|
||||||
|
local label = self:getParent():getChildByIndex(selectionChild)
|
||||||
|
table.insert(text, label:getSelection())
|
||||||
|
end
|
||||||
|
consoleBuffer.selectionText = table.concat(text, '\r\n')
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
label.onDragMove = function(self, mousePos, mouseMoved)
|
||||||
local parent = self:getParent()
|
local parent = self:getParent()
|
||||||
local selfIndex = parent:getChildIndex(self)
|
local selfIndex = parent:getChildIndex(self)
|
||||||
local child = parent:getChildByPos(mousePos)
|
local child = parent:getChildByPos(mousePos)
|
||||||
|
|
||||||
|
-- find out bounds children
|
||||||
|
if not child then
|
||||||
|
if mousePos.y >= parent:getLastChild():getY() then
|
||||||
|
child = parent:getLastChild()
|
||||||
|
elseif mousePos.y <= parent:getFirstChild():getY() then
|
||||||
|
child = parent:getFirstChild()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not child then return false end
|
||||||
|
|
||||||
local childIndex = parent:getChildIndex(child)
|
local childIndex = parent:getChildIndex(child)
|
||||||
|
|
||||||
-- remove old selection
|
-- remove old selection
|
||||||
invalidateSelection(self)
|
clearSelection(consoleBuffer)
|
||||||
|
|
||||||
-- choose new selection
|
-- update self selection
|
||||||
if child and child ~= self then
|
local textBegin = self:getTextPos(self:getLastClickPosition())
|
||||||
self.selection = {first = math.min(selfIndex, childIndex), last = math.max(selfIndex, childIndex)}
|
local textPos = self:getTextPos(mousePos)
|
||||||
for selectionChild = self.selection.first + 1, self.selection.last - 1 do
|
self:setSelection(textBegin, textPos)
|
||||||
|
|
||||||
|
consoleBuffer.selection = { first = math.min(selfIndex, childIndex), last = math.max(selfIndex, childIndex) }
|
||||||
|
|
||||||
|
-- update siblings selection
|
||||||
|
if child ~= self then
|
||||||
|
for selectionChild = consoleBuffer.selection.first + 1, consoleBuffer.selection.last - 1 do
|
||||||
parent:getChildByIndex(selectionChild):selectAll()
|
parent:getChildByIndex(selectionChild):selectAll()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -638,15 +641,14 @@ function addTabText(text, speaktype, tab, creatureName)
|
||||||
else
|
else
|
||||||
child:setSelection(string.len(child:getText()), textPos)
|
child:setSelection(string.len(child:getText()), textPos)
|
||||||
end
|
end
|
||||||
elseif not child then
|
|
||||||
-- TODO: out of bonding rect selection
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if consoleBuffer:getChildCount() > MAX_LINES then
|
if consoleBuffer:getChildCount() > MAX_LINES then
|
||||||
local child = consoleBuffer:getFirstChild()
|
local child = consoleBuffer:getFirstChild()
|
||||||
if child.selection then invalidateSelection(child) end
|
clearSelection(consoleBuffer)
|
||||||
child:destroy()
|
child:destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -709,13 +711,15 @@ function processMessageMenu(mousePos, mouseButton, creatureName, text, label, ta
|
||||||
|
|
||||||
menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
|
menu:addOption(tr('Copy name'), function () g_window.setClipboardText(creatureName) end)
|
||||||
end
|
end
|
||||||
local selectedText = getSelection(label)
|
local selection = tab.tabPanel:getChildById('consoleBuffer').selectionText
|
||||||
if #selectedText > 0 then
|
if selection and #selection > 0 then
|
||||||
menu:addOption(tr('Copy'), function() g_window.setClipboardText(selectedText) end, '(Ctrl+C)')
|
menu:addOption(tr('Copy'), function() g_window.setClipboardText(selection) end, '(Ctrl+C)')
|
||||||
end
|
end
|
||||||
|
if text then
|
||||||
menu:addOption(tr('Copy message'), function() g_window.setClipboardText(text) end)
|
menu:addOption(tr('Copy message'), function() g_window.setClipboardText(text) end)
|
||||||
menu:addOption(tr('Select all'), function() label:selectAll() end)
|
end
|
||||||
if tab.violations then
|
--menu:addOption(tr('Select all'), function() label:selectAll() end)
|
||||||
|
if tab.violations and creatureName then
|
||||||
menu:addSeparator()
|
menu:addSeparator()
|
||||||
menu:addOption(tr('Process') .. ' ' .. creatureName, function() processViolation(creatureName, text) end)
|
menu:addOption(tr('Process') .. ' ' .. creatureName, function() processViolation(creatureName, text) end)
|
||||||
menu:addOption(tr('Remove') .. ' ' .. creatureName, function() g_game.closeRuleViolation(creatureName) end)
|
menu:addOption(tr('Remove') .. ' ' .. creatureName, function() g_game.closeRuleViolation(creatureName) end)
|
||||||
|
|
|
@ -10,6 +10,8 @@ ConsoleLabel < UITextEdit
|
||||||
change-cursor-image: false
|
change-cursor-image: false
|
||||||
cursor-visible: false
|
cursor-visible: false
|
||||||
editable: false
|
editable: false
|
||||||
|
draggable: true
|
||||||
|
selectable: false
|
||||||
|
|
||||||
ConsolePhantomLabel < UILabel
|
ConsolePhantomLabel < UILabel
|
||||||
font: verdana-11px-antialised
|
font: verdana-11px-antialised
|
||||||
|
|
|
@ -659,7 +659,7 @@ void UITextEdit::onFocusChange(bool focused, Fw::FocusReason reason)
|
||||||
else
|
else
|
||||||
blinkCursor();
|
blinkCursor();
|
||||||
update(true);
|
update(true);
|
||||||
} else
|
} else if(m_selectable)
|
||||||
clearSelection();
|
clearSelection();
|
||||||
UIWidget::onFocusChange(focused, reason);
|
UIWidget::onFocusChange(focused, reason);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue