Skip to content

Commit

Permalink
[Console] Fix inserting the history request on a line outside of a pa…
Browse files Browse the repository at this point in the history
…rsed request
  • Loading branch information
yuliacech committed May 21, 2024
1 parent dc2e42e commit 67968c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,34 @@ describe('Editor actions provider', () => {
expect(editor.executeEdits).toHaveBeenCalledTimes(1);
expect(editor.executeEdits).toHaveBeenCalledWith('restoreFromHistory', [expectedEdit]);
});

it('insert at the beginning of the line, if no selected request', async () => {
// mock no parsed requests
mockGetParsedRequests.mockReturnValue([]);
// the position of the cursor is at the end of line 4
editor.getPosition.mockReturnValue({
lineNumber: 4,
column: 2,
} as monaco.Position);
editor.getSelection.mockReturnValue({
startLineNumber: 4,
endLineNumber: 4,
} as monaco.Selection);
await editorActionsProvider.restoreRequestFromHistory(testHistoryRequest);
const expectedRange = {
startLineNumber: 4,
startColumn: 1,
endLineNumber: 4,
endColumn: 1,
};
const expectedText = testHistoryRequest + '\n';
const expectedEdit = {
range: expectedRange,
text: expectedText,
forceMoveMarkers: true,
};
expect(editor.executeEdits).toHaveBeenCalledTimes(1);
expect(editor.executeEdits).toHaveBeenCalledWith('restoreFromHistory', [expectedEdit]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,15 @@ export class MonacoEditorActionsProvider {
prefix = '\n';
}
} else {
// if not inside a request, insert the request at the cursor position
if (!position) {
// if no cursor position, insert at the beginning
// if not inside a request, insert the request at the cursor line
if (position) {
// insert at the beginning of the cursor line
position = { lineNumber: position.lineNumber, column: 1 };
} else {
// otherwise insert on line 1
position = { lineNumber: 1, column: 1 };
}
suffix = '\n';
}
const edit: monaco.editor.IIdentifiedSingleEditOperation = {
range: {
Expand Down

0 comments on commit 67968c6

Please sign in to comment.