Repository: microsoft/vscode (TypeScript) — Bug Fix

Issue:
Shift click selection does not work on line number indecator
<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.69.2
- OS Version: macos 12.4

Trying to select a text section by shift clicking on to the line indecator does not work. This only appears when the origin cursor is a **cursor** (thus, a selection with 0 length). When the origin is already a selection this behaves as expected.

Steps to Reproduce: note how I press shift when clicking on the line number. And note how the origin is a cursor.

![vscodeSelectBugShort](https://user-images.githubusercontent.com/42389740/184802662-7d173622-1bd3-4a71-9813-8072e4853563.gif)





Discussion:
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.70.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!
Still persists in 1.70.1

Resolving patch:
diff --git a/src/vs/editor/common/cursor/cursorMoveCommands.ts b/src/vs/editor/common/cursor/cursorMoveCommands.ts
--- a/src/vs/editor/common/cursor/cursorMoveCommands.ts
+++ b/src/vs/editor/common/cursor/cursorMoveCommands.ts
@@ -181,7 +181,7 @@ export class CursorMoveCommands {
 				: viewModel.coordinatesConverter.convertModelPositionToViewPosition(position)
 		);
 
-		if (!inSelectionMode || !cursor.modelState.hasSelection()) {
+		if (!inSelectionMode) {
 			// Entering line selection for the first time
 			const lineCount = viewModel.model.getLineCount();
 
@@ -204,7 +204,7 @@ export class CursorMoveCommands {
 		if (position.lineNumber < enteringLineNumber) {
 
 			return CursorState.fromViewState(cursor.viewState.move(
-				cursor.modelState.hasSelection(), viewPosition.lineNumber, 1, 0
+				true, viewPosition.lineNumber, 1, 0
 			));
 
 		} else if (position.lineNumber > enteringLineNumber) {
@@ -219,14 +219,14 @@ export class CursorMoveCommands {
 			}
 
 			return CursorState.fromViewState(cursor.viewState.move(
-				cursor.modelState.hasSelection(), selectToViewLineNumber, selectToViewColumn, 0
+				true, selectToViewLineNumber, selectToViewColumn, 0
 			));
 
 		} else {
 
 			const endPositionOfSelectionStart = cursor.modelState.selectionStart.getEndPosition();
 			return CursorState.fromModelState(cursor.modelState.move(
-				cursor.modelState.hasSelection(), endPositionOfSelectionStart.lineNumber, endPositionOfSelectionStart.column, 0
+				true, endPositionOfSelectionStart.lineNumber, endPositionOfSelectionStart.column, 0
 			));
 
 		}


Test patch:
diff --git a/src/vs/editor/test/browser/controller/cursor.test.ts b/src/vs/editor/test/browser/controller/cursor.test.ts
--- a/src/vs/editor/test/browser/controller/cursor.test.ts
+++ b/src/vs/editor/test/browser/controller/cursor.test.ts
@@ -6108,6 +6108,26 @@ suite('Editor Controller', () => {
 			assertCursor(viewModel, new Selection(3, 7, 4, 7));
 		});
 	});
+
+	test('issue #158236: Shift click selection does not work on line number indicator', () => {
+		const model = createTextModel(
+			[
+				'just some text',
+				'and another line',
+				'and another one',
+			].join('\n')
+		);
+
+		withTestCodeEditor(model, {}, (editor, viewModel) => {
+			CoreNavigationCommands.MoveTo.runEditorCommand(null, editor, {
+				position: new Position(3, 5)
+			});
+			CoreNavigationCommands.LineSelectDrag.runEditorCommand(null, editor, {
+				position: new Position(2, 1)
+			});
+			assertCursor(viewModel, new Selection(3, 5, 2, 1));
+		});
+	});
 });
 
 suite('Undo stops', () => {