I am having trouble with the function ITextModel::Replace() in my plugin.
My plugin tries to replace codes such as [1Mmmm] by values such as April. Due to these codes often being too long to fit, my users often reduce the size of the inside of these codes, assuming that the replaced text will use the formatting of the first character (as happens when done manually).
To do this, as shown in the top example below, I replace the 1st character of the found text [ by the replacement text April, and then delete the remainder of the found text 1Mmmm]. This works well in all cases, except for kerning, which is lost.
As a workaround, I tried replacing the entire text [1Mmmm] by April in one unique call to Replace(). This solves the kerning issue, but as we can see above this does really weird things to the formatting of the replaced string.
Does anyone know what I am doing wrong, or is this a bug ?
Are you calling Replace() yourself? Read the programming guide on basics of commands, then use the factory interface ITextModelCmds.
Besides, to mimic "done manually" you'd better use the kUserTypeTextCmdBoss, also via that interface. It does plenty more things, including responder signalling, pre/post processing, the style handling that you're missing, maintain the selection.