toggle-components-library 1.37.0-beta.3 → 1.37.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toggle-components-library",
3
- "version": "1.37.0-beta.3",
3
+ "version": "1.37.0-beta.4",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -91,15 +91,26 @@ export default {
91
91
 
92
92
 
93
93
  updateContent(event) {
94
- // Limit the input to 50 characters
95
- if (event.target.innerText.length >= this.maxChars) {
96
- event.target.innerText = this.content;
94
+ const newText = event.target.innerText;
95
+
96
+ // If text exceeds maxChars, prevent the change
97
+ if (newText.length > this.maxChars) {
98
+ // Save current selection
99
+ const selection = window.getSelection();
100
+ const range = selection.getRangeAt(0);
101
+ const cursorOffset = range.startOffset;
97
102
 
98
- // Move the cursor to the end of the input
99
- document.getSelection().modify("move", "forward", "documentboundary");
103
+ // Restore previous content
104
+ event.target.innerText = this.content;
100
105
 
106
+ // Restore cursor position
107
+ const newRange = document.createRange();
108
+ newRange.setStart(event.target.firstChild || event.target, Math.min(cursorOffset, this.content.length));
109
+ newRange.collapse(true);
110
+ selection.removeAllRanges();
111
+ selection.addRange(newRange);
101
112
  } else {
102
- this.content = event.target.innerText;
113
+ this.content = newText;
103
114
  this.$emit('update:lastCrumb', this.content);
104
115
  }
105
116
  }