| 121 | } |
| 122 | |
| 123 | void FileEditController::openFileEditInEditor(const QString &editId) |
| 124 | { |
| 125 | LOG_MESSAGE(QString("Opening file edit in editor: %1").arg(editId)); |
| 126 | |
| 127 | auto edit = Context::ChangesManager::instance().getFileEdit(editId); |
| 128 | if (edit.editId.isEmpty()) { |
| 129 | emit errorOccurred(QString("File edit not found: %1").arg(editId)); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | Utils::FilePath filePath = Utils::FilePath::fromString(edit.filePath); |
| 134 | |
| 135 | Core::IEditor *editor = Core::EditorManager::openEditor(filePath); |
| 136 | if (!editor) { |
| 137 | emit errorOccurred(QString("Failed to open file in editor: %1").arg(edit.filePath)); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor); |
| 142 | if (textEditor && textEditor->editorWidget()) { |
| 143 | QTextDocument *doc = textEditor->editorWidget()->document(); |
| 144 | if (doc) { |
| 145 | QString currentContent = doc->toPlainText(); |
| 146 | int position = -1; |
| 147 | |
| 148 | if (edit.status == Context::ChangesManager::Applied && !edit.newContent.isEmpty()) { |
| 149 | position = currentContent.indexOf(edit.newContent); |
| 150 | } else if (!edit.oldContent.isEmpty()) { |
| 151 | position = currentContent.indexOf(edit.oldContent); |
| 152 | } |
| 153 | |
| 154 | if (position >= 0) { |
| 155 | QTextCursor cursor(doc); |
| 156 | cursor.setPosition(position); |
| 157 | textEditor->editorWidget()->setTextCursor(cursor); |
| 158 | textEditor->editorWidget()->centerCursor(); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | LOG_MESSAGE(QString("Opened file in editor: %1").arg(edit.filePath)); |
| 164 | } |
| 165 | |
| 166 | void FileEditController::updateFileEditStatus(const QString &editId, const QString &status) |
| 167 | { |
nothing calls this directly
no test coverage detected