| 105 | } |
| 106 | |
| 107 | void PropertyPreviewWidget::updateValue() |
| 108 | { |
| 109 | QString newValue = view->rootObject()->property("value").toString(); |
| 110 | |
| 111 | // set the cursor to the edited range, otherwise the view will jump if we call doc->endEditing() |
| 112 | //document->activeView()->setCursorPosition(KTextEditor::Cursor(valueRange.start.line, valueRange.start.column)); |
| 113 | if (valueRange.end().column() - valueRange.start().column() == newValue.size()) { |
| 114 | document->replaceText(valueRange, newValue); |
| 115 | } |
| 116 | else { |
| 117 | // the length of the text changed so don't replace it but remove the old |
| 118 | // and insert the new text. |
| 119 | KTextEditor::Document::EditingTransaction transaction(document); |
| 120 | document->removeText(valueRange); |
| 121 | document->insertText(valueRange.start(), newValue); |
| 122 | |
| 123 | valueRange.setRange( |
| 124 | valueRange.start(), |
| 125 | KTextEditor::Cursor(valueRange.start().line(), valueRange.start().column() + newValue.size()) |
| 126 | ); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | PropertyPreviewWidget::~PropertyPreviewWidget() |
| 131 | { |