@zzish/math-rich-input 0.1.30 → 0.1.32

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": "@zzish/math-rich-input",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "React component for user to enter rich text with embedded math equations.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "rollup-plugin-css-only": "^3.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "react": "^17.0.1",
44
- "react-dom": "^17.0.1"
43
+ "react": "^16.14.0",
44
+ "react-dom": "^16.14.0"
45
45
  }
46
46
  }
@@ -286,10 +286,11 @@ export default class MathRichInput extends React.Component {
286
286
  isExpertMode,
287
287
  selectedTab
288
288
  ) => {
289
+
289
290
  // rangeParams, isExpertMode and selectedTab can be null, in which case we will set them
290
291
  if (rangeParams === null) rangeParams = this.lastSetRangeParams;
291
-
292
- this.afterComponentUpdateData = { rangeParams, value };
292
+
293
+ this.afterComponentUpdateData = {rangeParams, value}
293
294
 
294
295
  let options = this.props.options || DEFAULT_OPTIONS;
295
296
  if (isExpertMode === null) isExpertMode = options.isExpertMode;
@@ -451,7 +452,7 @@ export default class MathRichInput extends React.Component {
451
452
  }
452
453
 
453
454
  if (deleteToEmpty) {
454
- console.log("deleteToEmpty");
455
+ // console.log("deleteToEmpty")
455
456
  let new_rangeParams = {
456
457
  startNodeIndex: 0,
457
458
  startOffset: 1,
@@ -467,7 +468,7 @@ export default class MathRichInput extends React.Component {
467
468
  this.props.useExpertMode,
468
469
  this.props.selectedTab
469
470
  );
470
- e.preventDefault();
471
+ e.preventDefault()
471
472
  return;
472
473
  }
473
474
 
@@ -580,22 +581,22 @@ export default class MathRichInput extends React.Component {
580
581
  let index = rangeParams.startNodeIndex;
581
582
  let offset = rangeParams.startOffset;
582
583
 
583
- console.log("handleKeyDownArrowLeft");
584
- console.log(rangeParams);
584
+ // console.log("handleKeyDownArrowLeft")
585
+ // console.log(rangeParams)
585
586
  let new_globalOffset = rangeParams.endGlobalOffset - 1;
586
- let new_rangeParams = null;
587
+ let new_rangeParams = null
587
588
  if (e.shiftKey && new_globalOffset > rangeParams.startGlobalOffset) {
588
- new_rangeParams = {
589
- startGlobalOffset: rangeParams.startGlobalOffset,
590
- endGlobalOffset: new_globalOffset,
591
- };
589
+ new_rangeParams = {
590
+ startGlobalOffset: rangeParams.startGlobalOffset,
591
+ endGlobalOffset: new_globalOffset,
592
+ }
592
593
  } else {
593
594
  new_rangeParams = {
594
595
  startGlobalOffset: new_globalOffset,
595
596
  endGlobalOffset: new_globalOffset,
596
597
  };
597
598
  }
598
- console.log(new_rangeParams);
599
+ // console.log(new_rangeParams)
599
600
  e.preventDefault();
600
601
  this._setRangeParams(new_rangeParams);
601
602
  return;
@@ -607,7 +608,7 @@ export default class MathRichInput extends React.Component {
607
608
  let index = rangeParams.startNodeIndex;
608
609
  let offset = rangeParams.startOffset;
609
610
 
610
- let new_rangeParams = null;
611
+ let new_rangeParams = null
611
612
  let new_globalOffset = rangeParams.endGlobalOffset + 1;
612
613
  if (e.shiftKey && new_globalOffset > rangeParams.startGlobalOffset) {
613
614
  new_rangeParams = {
@@ -775,7 +776,7 @@ export default class MathRichInput extends React.Component {
775
776
  else {
776
777
  e.preventDefault();
777
778
  this.accent = new_accent;
778
- console.log("Accent set: " + this.accent);
779
+ // console.log("Accent set: " + this.accent);
779
780
  return true;
780
781
  }
781
782
  if (new_char !== "") {
@@ -856,42 +857,44 @@ export default class MathRichInput extends React.Component {
856
857
  /(Win)/i.test(window.navigator.platform) &&
857
858
  e.ctrlKey &&
858
859
  (e.key === "6" || e.key === "^")
859
- )
860
- return;
861
- // otherwise
862
- if (e.key === "6" || e.key === "^" || e.key === "+" || e.key === "=")
863
- this.styleText(e, "Superscript");
864
- // Don't apply subscript if it is the browser command key for "smaller"
865
- // if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-")
866
- // return
867
- // if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-")
868
- // return
869
- // otherwise
870
- if (e.key === "-" || e.key === "_") this.styleText(e, "Subscript");
860
+ ) {
861
+ // do nothing
862
+ } else {
863
+ // otherwise
864
+ if (e.key === "6" || e.key === "^" || e.key === "+" || e.key === "=")
865
+ this.styleText(e, "Superscript");
866
+ // Don't apply subscript if it is the browser command key for "smaller"
867
+ // if (/(Win)/i.test(window.navigator.platform) && e.ctrlKey && e.key === "-")
868
+ // return
869
+ // if (/(Mac)/i.test(window.navigator.platform) && e.metaKey && e.key === "-")
870
+ // return
871
+ // otherwise
872
+ if (e.key === "-" || e.key === "_") this.styleText(e, "Subscript");
871
873
 
872
- e.preventDefault();
873
- return;
874
+ e.preventDefault();
875
+ return;
876
+ }
874
877
  }
875
878
 
876
879
  if ((e.metaKey || e.ctrlKey) && e.key === "v") {
877
- console.log("Executing paste");
880
+ // console.log("Executing paste");
878
881
  document.execCommand("paste");
879
882
  return;
880
883
  }
881
884
  if ((e.metaKey || e.ctrlKey) && e.key === "c") {
882
- console.log("Executing copy");
885
+ // console.log("Executing copy");
883
886
  document.execCommand("copy");
884
887
  return;
885
888
  }
886
889
  if ((e.metaKey || e.ctrlKey) && e.key === "x") {
887
- console.log("Executing cut");
890
+ // console.log("Executing cut");
888
891
  document.execCommand("cut");
889
892
  return;
890
893
  }
891
894
 
892
895
  // Ignore automatic key repeat presses on Windows so that we can show an accent bar on
893
896
  // long key press
894
- if (!/(Win)/i.test(window.navigator.platform)) {
897
+ if (/(Win)/i.test(window.navigator.platform)) {
895
898
  if (e.key === this.keyPressed && this.keyPressStartTime > 0) {
896
899
  if (
897
900
  e.key.length === 1 &&
@@ -921,10 +924,13 @@ export default class MathRichInput extends React.Component {
921
924
  key === "?" ||
922
925
  key === "!"
923
926
  ) {
924
- this.setState({ showAccentBar: !this.state.showAccentBar });
927
+ console.log("showing/hiding accent bar")
928
+ this.setState({ showAccentBar: !this.state.showAccentBar});
925
929
  } else {
930
+ console.log("hiding accent bar")
926
931
  this.setState({ showAccentBar: false });
927
932
  }
933
+ e.preventDefault()
928
934
  return;
929
935
  }
930
936
 
@@ -936,7 +942,10 @@ export default class MathRichInput extends React.Component {
936
942
  // (keyPressStartTime is reset to -1 on key up)
937
943
  if (this.keyPressStartTime < 0) {
938
944
  this.keyPressStartTime = Date.now();
939
- if (this.state.showAccentBar) this.setState({ showAccentBar: false });
945
+ if (this.state.showAccentBar) {
946
+ console.log("Hiding accent bar 2")
947
+ this.setState({ showAccentBar: false });
948
+ }
940
949
  }
941
950
 
942
951
  if (e.key === "Backspace") {
@@ -1021,17 +1030,14 @@ export default class MathRichInput extends React.Component {
1021
1030
  }
1022
1031
  }
1023
1032
 
1024
- if (this.handleKeyDownAccentHelper(e)) return;
1033
+ if (this.handleKeyDownAccentHelper(e))
1034
+ return;
1025
1035
 
1026
1036
  // Check if inserting character in element that starts with small space
1027
- if (
1028
- e.key.length === 1 && // ie, it's not something like "arrowLeft"
1029
- params.startOffset === 0 &&
1030
- this.nodeStartsWithSmallSpace(startNode)
1031
- ) {
1032
- console.log(
1033
- "Handling character input at start of text node with small space"
1034
- );
1037
+ if (e.key.length === 1 && // ie, it's not something like "arrowLeft"
1038
+ params.startOffset === 0 &&
1039
+ this.nodeStartsWithSmallSpace(startNode)) {
1040
+ // console.log("Handling character input at start of text node with small space")
1035
1041
  this.insertAfterSmallSpace(e.key, params);
1036
1042
  e.preventDefault();
1037
1043
  return;
@@ -1136,14 +1142,13 @@ export default class MathRichInput extends React.Component {
1136
1142
 
1137
1143
  handleInput = (event) => {
1138
1144
  try {
1139
- console.log("handleInput");
1145
+ // console.log("handleInput")
1140
1146
  let raw_text = elementToMarkedRawText(
1141
1147
  this.editableDiv,
1142
1148
  null,
1143
1149
  0,
1144
1150
  this.enableHtml()
1145
1151
  );
1146
- console.log("handleInput 2");
1147
1152
  const params = this._getRangeParams();
1148
1153
  if (params === null || params === undefined)
1149
1154
  console.error("Could not get range params from input field");
@@ -1182,7 +1187,7 @@ export default class MathRichInput extends React.Component {
1182
1187
 
1183
1188
  updateActiveButtons = () => {
1184
1189
  try {
1185
- console.log("updateActiveButtons");
1190
+ // console.log("updateActiveButtons")
1186
1191
  let rangeParams = this._getRangeParams();
1187
1192
  if (rangeParams === null || rangeParams === undefined) {
1188
1193
  console.warn(
@@ -1248,19 +1253,19 @@ export default class MathRichInput extends React.Component {
1248
1253
  console.warn("handlePaste called, but no clipboard data");
1249
1254
  return;
1250
1255
  }
1251
- for (let i = 0; i < clipboardData.types.length; i++)
1252
- console.log(
1253
- clipboardData.types[i] +
1254
- ": " +
1255
- clipboardData.getData(clipboardData.types[i])
1256
- );
1256
+ // for (let i = 0; i < clipboardData.types.length; i++)
1257
+ // console.log(
1258
+ // clipboardData.types[i] +
1259
+ // ": " +
1260
+ // clipboardData.getData(clipboardData.types[i])
1261
+ // );
1257
1262
  let pasteHtml = clipboardData.getData("text/html");
1258
1263
  if (pasteHtml !== null && pasteHtml.length > 0) {
1259
- console.log("** Paste html");
1260
- console.log(pasteHtml);
1264
+ // console.log("** Paste html");
1265
+ // console.log(pasteHtml);
1261
1266
  pasteHtml = sanitiseHtml(pasteHtml);
1262
- console.log("** Santised paste html");
1263
- console.log(pasteHtml);
1267
+ // console.log("** Santised paste html");
1268
+ // console.log(pasteHtml);
1264
1269
  this.insertHtml(pasteHtml);
1265
1270
  event.preventDefault();
1266
1271
  } else {
@@ -1301,7 +1306,7 @@ export default class MathRichInput extends React.Component {
1301
1306
 
1302
1307
  componentDidUpdate() {
1303
1308
  try {
1304
- console.log("componentDidUpdate");
1309
+ // console.log("componentDidUpdate")
1305
1310
  if (
1306
1311
  this.afterComponentUpdateData !== null &&
1307
1312
  this.afterComponentUpdateData !== undefined &&
@@ -1351,8 +1356,8 @@ export default class MathRichInput extends React.Component {
1351
1356
  console.error(
1352
1357
  "Could not find node with index: " + rangeParams.startNodeIndex
1353
1358
  );
1354
- console.log("Child nodes:");
1355
- console.log(this.editableDiv.childNodes);
1359
+ // console.log("Child nodes:");
1360
+ // console.log(this.editableDiv.childNodes);
1356
1361
  node = this._findFirstTextNode();
1357
1362
  offset = 0;
1358
1363
  }
@@ -1493,8 +1498,8 @@ export default class MathRichInput extends React.Component {
1493
1498
  let start_pos = this.markedRawText.indexOf(MARK);
1494
1499
  let end_pos = this.markedRawText.indexOf(MARK, start_pos + MARK.length);
1495
1500
  let oldRangeParams = this.getOldRangeParams();
1496
- console.log("Old range params");
1497
- console.log(oldRangeParams);
1501
+ // console.log("Old range params")
1502
+ // console.log(oldRangeParams)
1498
1503
 
1499
1504
  // Handle case of empty string returned
1500
1505
  if (latex === "") {
@@ -1717,20 +1722,29 @@ export default class MathRichInput extends React.Component {
1717
1722
  new_raw_text = removeMarks(
1718
1723
  insertCharacterBeforeMarks(raw_text, new_text)
1719
1724
  );
1720
- // console.log("New raw text:")
1721
- // console.log(new_raw_text)
1722
- // if (rangeParams.startNodeIndex === rangeParams.endNodeIndex &&
1723
- // rangeParams.startOffset === rangeParams.endOffset)
1724
- // new_rangeParams.startOffset = new_rangeParams.startOffset + new_text.length
1725
- new_rangeParams.endOffset = new_rangeParams.endOffset + new_text.length;
1726
- if (!selectInsertedText) {
1727
- new_rangeParams.startNodeIndex = new_rangeParams.endNodeIndex;
1728
- new_rangeParams.startOffset = new_rangeParams.endOffset;
1725
+
1726
+ // console.log("Range params before insert")
1727
+ // console.log(rangeParams)
1728
+
1729
+ if (selectInsertedText) {
1730
+ new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
1731
+ new_rangeParams.startOffset = rangeParams.endOffset;
1732
+ new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
1733
+ new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
1734
+ new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset;
1735
+ new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset+ new_text.length;
1736
+ } else {
1737
+ new_rangeParams.startNodeIndex = rangeParams.endNodeIndex;
1738
+ new_rangeParams.startOffset = rangeParams.endOffset + new_text.length;
1739
+ new_rangeParams.endNodeIndex = rangeParams.endNodeIndex;
1740
+ new_rangeParams.endOffset = rangeParams.endOffset + new_text.length;
1741
+ new_rangeParams.startGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
1742
+ new_rangeParams.endGlobalOffset = rangeParams.endGlobalOffset + new_text.length;
1729
1743
  }
1730
- // console.log("Setting new range params: ")
1744
+
1745
+ // console.log("Range params after insert")
1731
1746
  // console.log(new_rangeParams)
1732
- // console.log("Setting new mime-type: ")
1733
- // console.log(this.props.mimeType)
1747
+
1734
1748
  new_raw_text = removeEncodingIfPlainText(
1735
1749
  new_raw_text,
1736
1750
  this.props.mimeType,
@@ -1951,10 +1965,10 @@ export default class MathRichInput extends React.Component {
1951
1965
  this.enableHtml()
1952
1966
  );
1953
1967
 
1954
- console.log("Raw text before line insert");
1955
- console.log(raw_text);
1956
- console.log("Range params before line insert");
1957
- console.log(rangeParams);
1968
+ // console.log("Raw text before line insert")
1969
+ // console.log(raw_text)
1970
+ // console.log("Range params before line insert")
1971
+ // console.log(rangeParams)
1958
1972
 
1959
1973
  let new_raw_text = null;
1960
1974
  let new_rangeParams = { ...rangeParams };
@@ -1974,6 +1988,7 @@ export default class MathRichInput extends React.Component {
1974
1988
  new_rangeParams.startGlobalOffset++;
1975
1989
  new_rangeParams.endGlobalOffset++;
1976
1990
  }
1991
+
1977
1992
  } else {
1978
1993
  new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, "\n"));
1979
1994
  new_rangeParams.startOffset++;
@@ -1985,11 +2000,12 @@ export default class MathRichInput extends React.Component {
1985
2000
  this.props.mimeType,
1986
2001
  this.enableHtml()
1987
2002
  );
2003
+
2004
+ // console.log("New raw text after line insert")
2005
+ // console.log(new_raw_text)
2006
+ // console.log("New range params after line insert")
2007
+ // console.log(new_rangeParams)
1988
2008
 
1989
- console.log("New raw text after line insert");
1990
- console.log(new_raw_text);
1991
- console.log("New range params after line insert");
1992
- console.log(new_rangeParams);
1993
2009
 
1994
2010
  this.applyChangesToComponent(
1995
2011
  new_raw_text,
@@ -2009,39 +2025,34 @@ export default class MathRichInput extends React.Component {
2009
2025
  rangeParams = this._getRangeParams();
2010
2026
 
2011
2027
  if (rangeParams.startOffset !== 0)
2012
- console.warn(
2013
- "Unexpected startOffset " +
2014
- rangeParams.startOffset +
2015
- " in insertAfterSmallSpace"
2016
- );
2017
-
2028
+ console.warn("Unexpected startOffset "+rangeParams.startOffset+" in insertAfterSmallSpace")
2029
+
2018
2030
  let node = this._findNodeWithIndex(rangeParams.startNodeIndex);
2019
2031
  let raw_text = elementToMarkedRawText(
2020
- this.editableDiv,
2021
- node,
2022
- 1, // after small space
2023
- this.enableHtml()
2024
- );
2032
+ this.editableDiv,
2033
+ node,
2034
+ 1, // after small space
2035
+ this.enableHtml()
2036
+ );
2025
2037
 
2026
2038
  let new_raw_text = removeMarks(
2027
- insertCharacterBeforeMarks(raw_text, new_char)
2028
- );
2039
+ insertCharacterBeforeMarks(raw_text, new_char))
2029
2040
 
2030
2041
  let new_rangeParams = {
2031
- startNodeIndex: rangeParams.startNodeIndex,
2032
- startNodeOffset: 1 + new_char.length,
2033
- endNodeIndex: rangeParams.startNodeIndex,
2034
- endNodeOffset: 1 + new_char.length,
2035
- startGlobalOffset: rangeParams.startGlobalOffset + new_char.length,
2036
- endGlobalOffset: rangeParams.endGlobalOffset + new_char.length,
2037
- };
2038
-
2042
+ startNodeIndex:rangeParams.startNodeIndex,
2043
+ startNodeOffset:1+new_char.length,
2044
+ endNodeIndex:rangeParams.startNodeIndex,
2045
+ endNodeOffset:1+new_char.length,
2046
+ startGlobalOffset:rangeParams.startGlobalOffset+new_char.length,
2047
+ endGlobalOffset:rangeParams.endGlobalOffset+new_char.length,
2048
+ }
2049
+
2039
2050
  new_raw_text = removeEncodingIfPlainText(
2040
2051
  new_raw_text,
2041
2052
  this.props.mimeType,
2042
2053
  this.enableHtml()
2043
2054
  );
2044
-
2055
+
2045
2056
  this.applyChangesToComponent(
2046
2057
  new_raw_text,
2047
2058
  this.props.mimeType,
@@ -2052,7 +2063,7 @@ export default class MathRichInput extends React.Component {
2052
2063
  } catch (error) {
2053
2064
  console.error(error);
2054
2065
  }
2055
- }
2066
+ };
2056
2067
 
2057
2068
  insertAccentLetter = (event, old_char, new_char) => {
2058
2069
  try {
@@ -2070,24 +2081,18 @@ export default class MathRichInput extends React.Component {
2070
2081
  let new_raw_text = null;
2071
2082
  let new_rangeParams = null;
2072
2083
 
2073
- if (old_char === null) {
2074
- // insert new char
2075
- new_raw_text = removeMarks(
2076
- insertCharacterBeforeMarks(raw_text, new_char)
2077
- );
2084
+ if (old_char === null) { // insert new char
2085
+ new_raw_text = removeMarks(insertCharacterBeforeMarks(raw_text, new_char));
2078
2086
  new_rangeParams = {
2079
- startNodeIndex: rangeParams.startNodeIndex,
2080
- startOffset: rangeParams.startOffset + new_char.length,
2081
- endNodeIndex: rangeParams.startNodeIndex,
2082
- endOffset: rangeParams.startOffset + new_char.length,
2083
- startGlobalOffset: rangeParams.startGlobalOffset + new_char.length,
2084
- endGlobalOffset: rangeParams.startGlobalOffset + new_char.length,
2085
- };
2086
- } else {
2087
- // replace old char
2088
- new_raw_text = removeMarks(
2089
- replaceCharacterBeforeMarks(raw_text, new_char)
2090
- );
2087
+ startNodeIndex:rangeParams.startNodeIndex,
2088
+ startOffset:rangeParams.startOffset + new_char.length,
2089
+ endNodeIndex:rangeParams.startNodeIndex,
2090
+ endOffset:rangeParams.startOffset + new_char.length,
2091
+ startGlobalOffset:rangeParams.startGlobalOffset + new_char.length,
2092
+ endGlobalOffset:rangeParams.startGlobalOffset + new_char.length
2093
+ }
2094
+ } else { // replace old char
2095
+ new_raw_text = removeMarks(replaceCharacterBeforeMarks(raw_text, new_char));
2091
2096
  new_rangeParams = { ...rangeParams };
2092
2097
  }
2093
2098
 
@@ -2096,7 +2101,7 @@ export default class MathRichInput extends React.Component {
2096
2101
  this.props.mimeType,
2097
2102
  this.enableHtml()
2098
2103
  );
2099
-
2104
+
2100
2105
  this.applyChangesToComponent(
2101
2106
  new_raw_text,
2102
2107
  this.props.mimeType,
@@ -2112,6 +2117,7 @@ export default class MathRichInput extends React.Component {
2112
2117
  handleAccentButtonClick = (event, oldCharacter, newCharacter) => {
2113
2118
  try {
2114
2119
  this.insertAccentLetter(event, oldCharacter, newCharacter);
2120
+ console.log("Hiding accent bar 3")
2115
2121
  this.setState({ showAccentBar: false });
2116
2122
  } catch (error) {
2117
2123
  console.error(error);
@@ -2141,6 +2147,7 @@ export default class MathRichInput extends React.Component {
2141
2147
  onBlur();
2142
2148
  }
2143
2149
  try {
2150
+ console.log("Hiding accent bar 4")
2144
2151
  this.setState({ hasFocus: false, showAccentBar: false });
2145
2152
  } catch (error) {
2146
2153
  console.error(error);
@@ -382,8 +382,8 @@ function addTextForNode(node, arrayOfText, nodeToMark=null, offset=0, useHtmlMat
382
382
  // Marked nodes are useful if a node may need to be deleted and allows the node to be
383
383
  // deleted by stripping it out of the raw text.
384
384
  export function elementToMarkedRawText(element, nodeToMark=null, offset=0, useHtmlMath=true) {
385
- console.log("elementToMarkedRawText")
386
- console.log(element.innerHTML)
385
+ // console.log("elementToMarkedRawText")
386
+ // console.log(element.innerHTML)
387
387
  if (element.innerHTML === "<p><br></p>")
388
388
  throw new Error ("We are here")
389
389
  // console.log("Node to mark:")
@@ -734,14 +734,14 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset, result=null) {
734
734
  if (isTextNode(node)) {
735
735
  result.node = node
736
736
  result.lastTextNode = node
737
- console.log("Found text node \'"+node.nodeValue+"\' of length "+node.nodeValue.length)
738
- console.log("result.offset was: "+result.offset)
737
+ // console.log("Found text node \'"+node.nodeValue+"\' of length "+node.nodeValue.length)
738
+ // console.log("result.offset was: "+result.offset)
739
739
  result.offset += node.nodeValue.length
740
740
  if (nodeStartsWithSmallSpace(node)) {
741
- console.log("Text node starts with small space")
741
+ // console.log("Text node starts with small space")
742
742
  result.offset -= 1
743
743
  }
744
- console.log("result.offset now: "+result.offset)
744
+ // console.log("result.offset now: "+result.offset)
745
745
  return false
746
746
  }
747
747
  const childNodes = node.childNodes
@@ -762,10 +762,10 @@ function findNodeAndOffsetForGlobalOffset(node, globalOffset, result=null) {
762
762
  }
763
763
 
764
764
  if (node.nodeType === 1 && node.tagName === "P") {
765
- console.log("Leaving p node")
765
+ // console.log("Leaving p node")
766
766
  result.node = null
767
767
  result.offset ++
768
- console.log("result.offset now: "+result.offset)
768
+ // console.log("result.offset now: "+result.offset)
769
769
  }
770
770
  return false;
771
771
  }
@@ -786,9 +786,9 @@ export function findFirstTextNode(node) {
786
786
 
787
787
  function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset) {
788
788
  let result = {offset:0}
789
- console.log("Finding node and offset within: "+editableDiv.outerHTML)
789
+ // console.log("Finding node and offset within: "+editableDiv.outerHTML)
790
790
  findNodeAndOffsetForGlobalOffset(editableDiv, globalOffset, result)
791
- console.log(result)
791
+ // console.log(result)
792
792
 
793
793
  if (result.node === null) {
794
794
  if (globalOffset > 0 && result.lastTextNode !== null) {
@@ -823,7 +823,7 @@ function findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, globalOffset
823
823
 
824
824
  // https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
825
825
  export function getRangeParams(editableDiv) {
826
- console.log ("getRangeParams")
826
+ // console.log ("getRangeParams")
827
827
  // console.log("Inner html: "+editableDiv.innerHTML)
828
828
  const isSupported = typeof window.getSelection !== "undefined";
829
829
  if (!isSupported) {
@@ -907,11 +907,11 @@ function setRangeParamsFromGlobalOffsets(editableDiv, params) {
907
907
  findNodeAndOffsetForGlobalOffsetInEditableDiv(editableDiv, params.endGlobalOffset)
908
908
 
909
909
  if (startResult.node !== null) {
910
- console.log("Setting range to start in node:")
911
- console.log(" node type: "+startResult.node.nodeType)
912
- console.log(" tag name: "+startResult.node.tagName)
913
- console.log(" node value: "+startResult.node.nodeValue)
914
- console.log(" offset:"+startResult.offset)
910
+ // console.log("Setting range to start in node:")
911
+ // console.log(" node type: "+startResult.node.nodeType)
912
+ // console.log(" tag name: "+startResult.node.tagName)
913
+ // console.log(" node value: "+startResult.node.nodeValue)
914
+ // console.log(" offset:"+startResult.offset)
915
915
  } else {
916
916
  console.warn("Can't set range, null start node returned")
917
917
  return
@@ -944,13 +944,13 @@ export function setRangeParams(editableDiv, params) {
944
944
 
945
945
  // New way of doing things
946
946
  if (params.startGlobalOffset !== null && params.startGlobalOffset !== undefined) {
947
- console.log("Setting range from global offsets")
947
+ // console.log("Setting range from global offsets")
948
948
  setRangeParamsFromGlobalOffsets(editableDiv, params)
949
949
  return
950
950
  }
951
951
 
952
952
  // Otherwise use the old way of doing things
953
- console.log("Setting range from node index and local offset")
953
+ // console.log("Setting range from node index and local offset")
954
954
 
955
955
  if (params.startNodeIndex === null || params.startNodeIndex === undefined) {
956
956
  console.error("Can't set range params: params.startNodeIndex === "+params.startNodeIndex)
@@ -987,17 +987,17 @@ export function setRangeParams(editableDiv, params) {
987
987
  let startNode = findNodeWithIndex(editableDiv, params.startNodeIndex)
988
988
  let endNode = findNodeWithIndex(editableDiv, params.endNodeIndex)
989
989
 
990
- console.log("Setting range to start in node:")
991
- console.log(" node type: "+startNode.nodeType)
992
- console.log(" tag name: "+startNode.tagName)
993
- console.log(" node value: "+startNode.nodeValue)
994
- console.log(" offset:"+startOffset)
995
-
996
- console.log("Setting range to end in node:")
997
- console.log(" node type: "+endNode.nodeType)
998
- console.log(" tag name: "+endNode.tagName)
999
- console.log(" node value: "+endNode.nodeValue)
1000
- console.log(" offset:"+endOffset)
990
+ // console.log("Setting range to start in node:")
991
+ // console.log(" node type: "+startNode.nodeType)
992
+ // console.log(" tag name: "+startNode.tagName)
993
+ // console.log(" node value: "+startNode.nodeValue)
994
+ // console.log(" offset:"+startOffset)
995
+
996
+ // console.log("Setting range to end in node:")
997
+ // console.log(" node type: "+endNode.nodeType)
998
+ // console.log(" tag name: "+endNode.tagName)
999
+ // console.log(" node value: "+endNode.nodeValue)
1000
+ // console.log(" offset:"+endOffset)
1001
1001
 
1002
1002
  // Set range in document
1003
1003
  if (startNode === null) {