Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit ec63dfe

Browse files
authored
Merge pull request #47 from withspectrum/fixing-code-blocks
Fixing blockChange selection and update react and react-dom
2 parents 59e0b5e + 48bffaa commit ec63dfe

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
"postcss-loader": "^1.1.1",
7777
"prettier": "^1.7.0",
7878
"prismjs": "^1.6.0",
79-
"react": "^15.4.1",
79+
"react": "16.2.x",
8080
"react-addons-pure-render-mixin": "^15.4.1",
8181
"react-addons-test-utils": "^15.4.1",
82-
"react-dom": "^15.4.1",
82+
"react-dom": "16.2.0",
8383
"react-github-corner": "^2.0.0",
8484
"react-github-fork-ribbon": "^0.4.4",
8585
"react-test-renderer": "^16.2.0",

src/modifiers/changeCurrentBlockType.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@ const changeCurrentBlockType = (
77
blockMetadata = {}
88
) => {
99
const currentContent = editorState.getCurrentContent();
10-
const selection = editorState.getSelection();
10+
let selection = editorState.getSelection();
1111
const key = selection.getStartKey();
1212
const blockMap = currentContent.getBlockMap();
1313
const block = blockMap.get(key);
1414
const data = block.getData().merge(blockMetadata);
1515
const newBlock = block.merge({ type, data, text: text });
16+
17+
const lastOffset = text.length;
18+
19+
if (selection.getFocusOffset() > lastOffset) {
20+
selection = selection.merge({
21+
anchorOffset: lastOffset,
22+
focusOffset: lastOffset,
23+
});
24+
}
25+
1626
const newContentState = currentContent.merge({
1727
blockMap: blockMap.set(key, newBlock),
1828
selectionAfter: selection,
1929
});
30+
2031
return EditorState.push(editorState, newContentState, "change-block-type");
2132
};
2233

yarn.lock

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,14 +5273,14 @@ react-deep-force-update@^1.0.0:
52735273
version "1.1.1"
52745274
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.1.1.tgz#bcd31478027b64b3339f108921ab520b4313dc2c"
52755275

5276-
react-dom@^15.4.1:
5277-
version "15.6.1"
5278-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.1.tgz#2cb0ed4191038e53c209eb3a79a23e2a4cf99470"
5276+
react-dom@16.2.0:
5277+
version "16.2.0"
5278+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.2.0.tgz#69003178601c0ca19b709b33a83369fe6124c044"
52795279
dependencies:
5280-
fbjs "^0.8.9"
5280+
fbjs "^0.8.16"
52815281
loose-envify "^1.1.0"
5282-
object-assign "^4.1.0"
5283-
prop-types "^15.5.10"
5282+
object-assign "^4.1.1"
5283+
prop-types "^15.6.0"
52845284

52855285
react-github-corner@^2.0.0:
52865286
version "2.0.0"
@@ -5326,15 +5326,14 @@ react@*:
53265326
object-assign "^4.1.0"
53275327
prop-types "^15.5.10"
53285328

5329-
react@^15.4.1:
5330-
version "15.6.2"
5331-
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
5329+
react@16.2.x:
5330+
version "16.2.0"
5331+
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
53325332
dependencies:
5333-
create-react-class "^15.6.0"
5334-
fbjs "^0.8.9"
5333+
fbjs "^0.8.16"
53355334
loose-envify "^1.1.0"
5336-
object-assign "^4.1.0"
5337-
prop-types "^15.5.10"
5335+
object-assign "^4.1.1"
5336+
prop-types "^15.6.0"
53385337

53395338
read-pkg-up@^1.0.1:
53405339
version "1.0.1"

0 commit comments

Comments
 (0)