我正在使用 Gtk2Hs,所有这些 GTK 的东西对我来说都是新的。我正在使用TextView
. 我想用一些新文本替换当前选择的文本,并选择新文本。我能想到的最接近的是:
-- Create marks so I can "remember" where the selection was
(startIter, stopIter) <- textBufferGetSelectionBounds buffer
startMark <- textBufferCreateMark buffer (Just "start") startIter True
stopMark <- textBufferCreateMark buffer (Just "stop") stopIter True
-- Delete the currently selected text
textBufferDeleteSelection buffer True True
-- now startIter and stopIter are no longer valid
-- Insert the new text
somehow convert startMark to startIter2 ???
textBufferInsert buffer startIter2 text
-- now startIter2 is no longer valid
-- Select the new text
somehow convert startMark to startIter3 ???
somehow convert stopMark to stopIter3 ???
textBufferSelectRange buffer startIter3 stopIter3
我发现设置选择的唯一功能需要TextIter
s,而不是TextMark
s。但是我还没有找到任何函数来从 TextMark 中获取 TextIter。这是正确的程序吗?