You are on page 1of 1

CHAPTER 2: Text Story text 54

Deleting text from a story


You can delete a range of text from a story, using text commands or via a text selection.

Solution

If there is a valid text selection, use ITextEditSuite::Delete to delete selected text (after testing
ITextEditSuite::CanEditText to determine whether the operation is allowed).

To delete an arbitrary range of text, use the command generated by ITextModelCmds::DeleteCmd.


ITextModelCmds is available on kTextStoryBoss.

Before performing the modification, check the model to ensure it is not locked
(ITextModel::IsModelLocked).

Sample code

SnpManipulateTextModel::DeleteText

Replacing text in a story


You can replace a range of text with alternative text.

Solution

Use the command generated by ITextModelCmds::ReplaceCmd to replace text within a story.

Put the replaced data into a reference counted K2::shared_ptr with type WideString, and pass it into the
InsertCmd, so the memory occupied by the data is purged when no one is referencing it. For more
information, see K2SmartPtr.h.

Before performing the modification, check the model to ensure it is not locked
(ITextModel::IsModelLocked).

Sample code

SnpManipulateTextModel::ReplaceText

Copying text within and between stories


You can programmatically copy text within or across text stories.

Solution

To copy text within and between stories, use the command provided by the
ITextUtils::QueryCopyStoryCommand utility facade. Variants of this API allow common use cases of text
copy to be handled; for example, copying a range from source to a range in the destination and copying
the complete source story to the end of the destination story.

You might also like