From 257d4a16afb64b5caf24ce4fce014f85cecc5348 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20James?= <gael.james@aisin-europe.com>
Date: Mon, 4 Mar 2024 16:47:31 +0100
Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Add=20setup=20property=20FocusO?=
 =?UTF-8?q?nCreation?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CodeMirror6/Models/CodeMirrorSetup.cs | 7 ++++++-
 CodeMirror6/NodeLib/src/CmSetup.ts    | 1 +
 CodeMirror6/NodeLib/src/index.ts      | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/CodeMirror6/Models/CodeMirrorSetup.cs b/CodeMirror6/Models/CodeMirrorSetup.cs
index 3babaf0b..2e4a7003 100644
--- a/CodeMirror6/Models/CodeMirrorSetup.cs
+++ b/CodeMirror6/Models/CodeMirrorSetup.cs
@@ -109,5 +109,10 @@ public CodeMirrorSetup()
     /// <summary>
     /// Whether to show the debug logs
     /// </summary>
-    [JsonPropertyName("debugLogs")] public bool DebugLogs { get; init; } = false;
+    [JsonPropertyName("debugLogs")] public bool DebugLogs { get; init; }
+
+    /// <summary>
+    /// Whether to focus on the editor when it is created
+    /// </summary>
+    [JsonPropertyName("focusOnCreation")] public bool FocusOnCreation { get; init; }
 }
diff --git a/CodeMirror6/NodeLib/src/CmSetup.ts b/CodeMirror6/NodeLib/src/CmSetup.ts
index 63305fe8..9349bc79 100644
--- a/CodeMirror6/NodeLib/src/CmSetup.ts
+++ b/CodeMirror6/NodeLib/src/CmSetup.ts
@@ -22,4 +22,5 @@ export class CmSetup
     public bindValueMode: string
     public krokiUrl: string
     public debugLogs: boolean
+    public focusOnCreation: boolean
 }
diff --git a/CodeMirror6/NodeLib/src/index.ts b/CodeMirror6/NodeLib/src/index.ts
index 8ebdc77a..9543204d 100644
--- a/CodeMirror6/NodeLib/src/index.ts
+++ b/CodeMirror6/NodeLib/src/index.ts
@@ -218,7 +218,7 @@ export async function initCodeMirror(
             scrollTo: setup.scrollToEnd === true ? initialScrollEffect : null,
         })
 
-        if (setup.scrollToEnd === true) {
+        if (setup.focusOnCreation === true) {
             CMInstances[id].view.focus()
         }
 

From 7abc22cac14172300cb08ae2bdb6c4bda1d070b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20James?= <gael.james@aisin-europe.com>
Date: Mon, 4 Mar 2024 16:48:31 +0100
Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Force=20scroll=20to=20start?=
 =?UTF-8?q?=20of=20document=20if=20not=20scrolling=20to=20end,=20on=20crea?=
 =?UTF-8?q?tion?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CodeMirror6/NodeLib/src/index.ts | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/CodeMirror6/NodeLib/src/index.ts b/CodeMirror6/NodeLib/src/index.ts
index 9543204d..c72faa67 100644
--- a/CodeMirror6/NodeLib/src/index.ts
+++ b/CodeMirror6/NodeLib/src/index.ts
@@ -199,7 +199,13 @@ export async function initCodeMirror(
         const textInLocalStorage = localStorage.getItem(initialConfig.localStorageKey)
         const initialDoc = textInLocalStorage ? textInLocalStorage : initialConfig.doc
 
-        const initialScrollEffect = EditorView.scrollIntoView((initialDoc && setup.scrollToEnd === true) ? initialDoc.length : 0, { y: setup.scrollToEnd === true ? 'end' : 'start' })
+        const initialScrollPosition = (initialDoc && setup.scrollToEnd === true)
+            ? initialDoc.length
+            : 0
+        const initialScrollEffect = EditorView.scrollIntoView(
+            initialScrollPosition,
+            { y: setup.scrollToEnd === true ? 'end' : 'start' }
+        )
         const docLines = initialDoc?.split(/\r\n|\r|\n/) ?? [initialDoc]
         const text = Text.of(docLines)
         const textLength = text?.length ?? 0
@@ -215,7 +221,7 @@ export async function initCodeMirror(
         CMInstances[id].view = new EditorView({
             state: CMInstances[id].state,
             parent: parentDiv,
-            scrollTo: setup.scrollToEnd === true ? initialScrollEffect : null,
+            scrollTo: initialScrollEffect,
         })
 
         if (setup.focusOnCreation === true) {

From ef9d2ef8e72365e8dd484ed504fd2c849248a3ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20James?= <gael.james@aisin-europe.com>
Date: Mon, 4 Mar 2024 16:48:51 +0100
Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9D=20Update=20changelog=20for=200?=
 =?UTF-8?q?.8.2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CHANGELOG.md     | 10 ++++++++++
 NEW_CHANGELOG.md |  8 ++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54daa923..802f7601 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
 # Changelog
 
+## 0.8.2 - 2024-03-04
+
+### ✨ Introduce new features
+
+- Add setup property FocusOnCreation
+
+### 🐛 Fix a bug
+
+- Force scroll to start of document if not scrolling to end, on creation
+
 ## 0.8.1 - 2024-03-04
 
 ### ⚡️ Improve performance
diff --git a/NEW_CHANGELOG.md b/NEW_CHANGELOG.md
index 359943fc..63ced49f 100644
--- a/NEW_CHANGELOG.md
+++ b/NEW_CHANGELOG.md
@@ -1,7 +1,7 @@
-### ⚡️ Improve performance
+### ✨ Introduce new features
 
-- Add a cancellation token to help remove errors in Blazor Server with pre-rendering
+- Add setup property FocusOnCreation
 
-### 🚚 Move or rename resources (e.g., files, paths)
+### 🐛 Fix a bug
 
-- Move code blocks for consistency
+- Force scroll to start of document if not scrolling to end, on creation

From 6c48cd80ba6de99dbdf99c5861e5583ce5e1fe6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20James?= <gael.james@aisin-europe.com>
Date: Mon, 4 Mar 2024 16:48:52 +0100
Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20to=200.8.2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CodeMirror6/CodeMirror6.csproj                                  | 2 +-
 Examples.BlazorServer/Examples.BlazorServer.csproj              | 2 +-
 .../Examples.BlazorServerInteractive.csproj                     | 2 +-
 Examples.BlazorWasm/Examples.BlazorWasm.csproj                  | 2 +-
 Examples.Common/Examples.Common.csproj                          | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/CodeMirror6/CodeMirror6.csproj b/CodeMirror6/CodeMirror6.csproj
index acfde7f9..d88cc6da 100644
--- a/CodeMirror6/CodeMirror6.csproj
+++ b/CodeMirror6/CodeMirror6.csproj
@@ -9,7 +9,7 @@
     <AssemblyName>GaelJ.BlazorCodeMirror6</AssemblyName>
     <IsPackable>true</IsPackable>
     <PackageId>GaelJ.BlazorCodeMirror6</PackageId>
-    <Version>0.8.1</Version>
+    <Version>0.8.2</Version>
     <IncludeSymbols>true</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
diff --git a/Examples.BlazorServer/Examples.BlazorServer.csproj b/Examples.BlazorServer/Examples.BlazorServer.csproj
index 490d9ac0..7105573b 100644
--- a/Examples.BlazorServer/Examples.BlazorServer.csproj
+++ b/Examples.BlazorServer/Examples.BlazorServer.csproj
@@ -4,7 +4,7 @@
     <Nullable>enable</Nullable>
     <IsPackable>false</IsPackable>
     <ImplicitUsings>enable</ImplicitUsings>
-    <Version>0.8.1</Version>
+    <Version>0.8.2</Version>
   </PropertyGroup>
   <ItemGroup>
     <SupportedPlatform Include="browser" />
diff --git a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj
index 47a5e172..3a6603c4 100644
--- a/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj
+++ b/Examples.BlazorServerInteractive/Examples.BlazorServerInteractive.csproj
@@ -4,7 +4,7 @@
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
     <IsPackable>false</IsPackable>
-    <Version>0.8.1</Version>
+    <Version>0.8.2</Version>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Sentry.AspNetCore" Version="4.1.0" />
diff --git a/Examples.BlazorWasm/Examples.BlazorWasm.csproj b/Examples.BlazorWasm/Examples.BlazorWasm.csproj
index fcf8257e..9e742c83 100644
--- a/Examples.BlazorWasm/Examples.BlazorWasm.csproj
+++ b/Examples.BlazorWasm/Examples.BlazorWasm.csproj
@@ -4,7 +4,7 @@
     <Nullable>enable</Nullable>
     <ImplicitUsings>enable</ImplicitUsings>
     <IsPackable>false</IsPackable>
-    <Version>0.8.1</Version>
+    <Version>0.8.2</Version>
   </PropertyGroup>
   <ItemGroup>
     <SupportedPlatform Include="browser-wasm" />
diff --git a/Examples.Common/Examples.Common.csproj b/Examples.Common/Examples.Common.csproj
index e968d278..5c8144ff 100644
--- a/Examples.Common/Examples.Common.csproj
+++ b/Examples.Common/Examples.Common.csproj
@@ -5,7 +5,7 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
     <IsPackable>false</IsPackable>
-    <Version>0.8.1</Version>
+    <Version>0.8.2</Version>
   </PropertyGroup>
   <ItemGroup>
     <SupportedPlatform Include="browser" />