mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 04:50:09 +08:00
* fix: #893 #892 * update change log * update checkNotSameTokens * fix error when delete at the end of inline math or ruby tag
This commit is contained in:
parent
c0f333d9a2
commit
82d4c74f62
2
.github/CHANGELOG.md
vendored
2
.github/CHANGELOG.md
vendored
@ -113,6 +113,8 @@ foo<section>bar</section>zar
|
|||||||
- Fixed list parse error [more info](https://github.com/marktext/marktext/issues/831#issuecomment-477719256)
|
- Fixed list parse error [more info](https://github.com/marktext/marktext/issues/831#issuecomment-477719256)
|
||||||
- Fixed source code mode tab switching
|
- Fixed source code mode tab switching
|
||||||
- Fixed source code mode to preview switching
|
- Fixed source code mode to preview switching
|
||||||
|
- Mark Text didn't remove highlight when I delete the markdown symbol like * or `. (#893)
|
||||||
|
- After delete ``` at the beginning to paragraph by backspace, then type other text foo, the color will be strange, if you type 1. bar. error happened. (#892)
|
||||||
|
|
||||||
### 0.13.65
|
### 0.13.65
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import selection from '../selection'
|
import selection from '../selection'
|
||||||
import { findNearestParagraph, findOutMostParagraph } from '../selection/dom'
|
import { findNearestParagraph, findOutMostParagraph } from '../selection/dom'
|
||||||
|
import { tokenizer, generator } from '../parser/parse'
|
||||||
|
|
||||||
const backspaceCtrl = ContentState => {
|
const backspaceCtrl = ContentState => {
|
||||||
ContentState.prototype.checkBackspaceCase = function () {
|
ContentState.prototype.checkBackspaceCase = function () {
|
||||||
@ -101,11 +102,51 @@ const backspaceCtrl = ContentState => {
|
|||||||
|
|
||||||
ContentState.prototype.backspaceHandler = function (event) {
|
ContentState.prototype.backspaceHandler = function (event) {
|
||||||
const { start, end } = selection.getCursorRange()
|
const { start, end } = selection.getCursorRange()
|
||||||
|
|
||||||
if (!start || !end) {
|
if (!start || !end) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const startBlock = this.getBlock(start.key)
|
const startBlock = this.getBlock(start.key)
|
||||||
const endBlock = this.getBlock(end.key)
|
const endBlock = this.getBlock(end.key)
|
||||||
|
// fix: #897
|
||||||
|
const { text } = startBlock
|
||||||
|
const tokens = tokenizer(text)
|
||||||
|
let needRender = false
|
||||||
|
let preToken = null
|
||||||
|
for (const token of tokens) {
|
||||||
|
// handle delete the second $ in inline_math.
|
||||||
|
if (
|
||||||
|
token.range.end === start.offset &&
|
||||||
|
token.type === 'inline_math'
|
||||||
|
) {
|
||||||
|
needRender = true
|
||||||
|
token.raw = token.raw.substr(0, token.raw.length - 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// handle pre token is a <ruby> html tag, need preventdefault.
|
||||||
|
if (
|
||||||
|
token.range.start + 1 === start.offset &&
|
||||||
|
preToken &&
|
||||||
|
preToken.type === 'html_tag' &&
|
||||||
|
preToken.tag === 'ruby'
|
||||||
|
) {
|
||||||
|
needRender = true
|
||||||
|
token.raw = token.raw.substr(1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
preToken = token
|
||||||
|
}
|
||||||
|
if (needRender) {
|
||||||
|
startBlock.text = generator(tokens)
|
||||||
|
event.preventDefault()
|
||||||
|
start.offset--
|
||||||
|
end.offset--
|
||||||
|
this.cursor = {
|
||||||
|
start,
|
||||||
|
end
|
||||||
|
}
|
||||||
|
return this.partialRender()
|
||||||
|
}
|
||||||
// fix: #67 problem 1
|
// fix: #67 problem 1
|
||||||
if (startBlock.icon) return event.preventDefault()
|
if (startBlock.icon) return event.preventDefault()
|
||||||
// fix: unexpect remove all editor html. #67 problem 4
|
// fix: unexpect remove all editor html. #67 problem 4
|
||||||
|
@ -41,6 +41,42 @@ const inputCtrl = ContentState => {
|
|||||||
return tokens.filter(t => t.type === 'inline_math').some(t => offset >= t.range.start && offset <= t.range.end)
|
return tokens.filter(t => t.type === 'inline_math').some(t => offset >= t.range.start && offset <= t.range.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentState.prototype.checkNotSameToken = function (oldText, text) {
|
||||||
|
const oldTokens = tokenizer(oldText)
|
||||||
|
const tokens = tokenizer(text)
|
||||||
|
|
||||||
|
const oldCache = {}
|
||||||
|
const cache = {}
|
||||||
|
|
||||||
|
for (const { type } of oldTokens) {
|
||||||
|
if (oldCache[type]) {
|
||||||
|
oldCache[type]++
|
||||||
|
} else {
|
||||||
|
oldCache[type] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const { type } of tokens) {
|
||||||
|
if (cache[type]) {
|
||||||
|
cache[type]++
|
||||||
|
} else {
|
||||||
|
cache[type] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(oldCache).length !== Object.keys(cache).length) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key of Object.keys(oldCache)) {
|
||||||
|
if (!cache[key] || oldCache[key] !== cache[key]) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
ContentState.prototype.inputHandler = function (event) {
|
ContentState.prototype.inputHandler = function (event) {
|
||||||
const { start, end } = selection.getCursorRange()
|
const { start, end } = selection.getCursorRange()
|
||||||
if (!start || !end) {
|
if (!start || !end) {
|
||||||
@ -135,6 +171,10 @@ const inputCtrl = ContentState => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.checkNotSameToken(block.text, text)) {
|
||||||
|
needRender = true
|
||||||
|
}
|
||||||
block.text = text
|
block.text = text
|
||||||
if (beginRules['reference_definition'].test(text)) {
|
if (beginRules['reference_definition'].test(text)) {
|
||||||
needRenderAll = true
|
needRenderAll = true
|
||||||
|
Loading…
Reference in New Issue
Block a user