+void Controller::TextUpdater::InsertTextAnchor(Controller& controller, int numberOfCharacters, CharacterIndex previousCursorIndex)
+{
+ Controller::Impl& impl = *controller.mImpl;
+ ModelPtr& model = impl.mModel;
+ LogicalModelPtr& logicalModel = model->mLogicalModel;
+
+ for(auto& anchor : logicalModel->mAnchors)
+ {
+ if(anchor.endIndex < previousCursorIndex) // [anchor] CUR
+ {
+ continue;
+ }
+ if(anchor.startIndex < previousCursorIndex) // [anCURr]
+ {
+ anchor.endIndex += numberOfCharacters;
+ }
+ else // CUR [anchor]
+ {
+ anchor.startIndex += numberOfCharacters;
+ anchor.endIndex += numberOfCharacters;
+ }
+ DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::InsertTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
+ }
+}
+
+void Controller::TextUpdater::RemoveTextAnchor(Controller& controller, int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
+{
+ Controller::Impl& impl = *controller.mImpl;
+ ModelPtr& model = impl.mModel;
+ LogicalModelPtr& logicalModel = model->mLogicalModel;
+ Vector<Anchor>::Iterator it = logicalModel->mAnchors.Begin();
+
+ while(it != logicalModel->mAnchors.End())
+ {
+ Anchor& anchor = *it;
+
+ if(anchor.endIndex <= previousCursorIndex && cursorOffset == 0) // [anchor] CUR >>
+ {
+ // Nothing happens.
+ }
+ else if(anchor.endIndex <= previousCursorIndex && cursorOffset == -1) // [anchor] << CUR
+ {
+ int endIndex = anchor.endIndex;
+ int offset = previousCursorIndex - endIndex;
+ int index = endIndex - (numberOfCharacters - offset);
+
+ if(index < endIndex)
+ {
+ endIndex = index;
+ }
+
+ if((int)anchor.startIndex >= endIndex)
+ {
+ if(anchor.href)
+ {
+ delete[] anchor.href;
+ }
+ it = logicalModel->mAnchors.Erase(it);
+ continue;
+ }
+ else
+ {
+ anchor.endIndex = endIndex;
+ }
+ }
+ else if(anchor.startIndex >= previousCursorIndex && cursorOffset == -1) // << CUR [anchor]
+ {
+ anchor.startIndex -= numberOfCharacters;
+ anchor.endIndex -= numberOfCharacters;
+ }
+ else if(anchor.startIndex >= previousCursorIndex && cursorOffset == 0) // CUR >> [anchor]
+ {
+ int startIndex = anchor.startIndex;
+ int endIndex = anchor.endIndex;
+ int index = previousCursorIndex + numberOfCharacters - 1;
+
+ if(startIndex > index)
+ {
+ anchor.startIndex -= numberOfCharacters;
+ anchor.endIndex -= numberOfCharacters;
+ }
+ else if(endIndex > index + 1)
+ {
+ anchor.endIndex -= numberOfCharacters;
+ }
+ else
+ {
+ if(anchor.href)
+ {
+ delete[] anchor.href;
+ }
+ it = logicalModel->mAnchors.Erase(it);
+ continue;
+ }
+ }
+ else if(cursorOffset == -1) // [<< CUR]
+ {
+ int startIndex = anchor.startIndex;
+ int index = previousCursorIndex - numberOfCharacters;
+
+ if(startIndex >= index)
+ {
+ anchor.startIndex = index;
+ }
+ anchor.endIndex -= numberOfCharacters;
+ }
+ else if(cursorOffset == 0) // [CUR >>]
+ {
+ anchor.endIndex -= numberOfCharacters;
+ }
+ else
+ {
+ // When this condition is reached, someting is wrong.
+ DALI_LOG_ERROR("Controller::RemoveTextAnchor[%p] Invaild state cursorOffset[%d]\n", &controller, cursorOffset);
+ }
+
+ DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
+
+ it++;
+ }
+}
+