0

私は Gtk2H を使用していますが、この 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

選択を設定するために私が見つけた唯一の関数は、TextItersではなくTextMarksを必要とします。しかし、TextMark から TextIter を取得する関数を見つけることができませんでした。これは正しい手順ですか?

4

2 に答える 2

0

OK、 を使用してそれを行う方法を見つけましたTextMarks。私が探していた機能はtextBufferGetIterAtMark.

textBufferReplaceSelection 
  ∷ TextBufferClass self ⇒ self → String → IO ()
textBufferReplaceSelection buffer text = do
  -- Create marks so I can "remember" where the selection was
  (startIter, stopIter) <- textBufferGetSelectionBounds buffer
  startMark <- textBufferCreateMark buffer (Just "start") startIter False
  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
  startIter2 <- textBufferGetIterAtMark buffer startMark
  textBufferInsert buffer startIter2 text
  -- now startIter2 is no longer valid

  -- Select the new text
  startIter3 <- textBufferGetIterAtMark buffer startMark
  stopIter3 <- textBufferGetIterAtMark buffer stopMark
  textBufferSelectRange buffer startIter3 stopIter3
于 2013-04-04T17:43:40.567 に答える