mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Fix Trix to use paragraphs and break on return
This commit is contained in:
parent
02ecf7ccfe
commit
b0dbccd283
@ -249,11 +249,33 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return target
|
return target
|
||||||
|
},
|
||||||
|
enableBreakParagraphOnReturn() {
|
||||||
|
// Trix works with divs by default, we want paragraphs instead
|
||||||
|
Trix.config.blockAttributes.default.tagName = 'p'
|
||||||
|
// Enable break paragraph on Enter (Shift + Enter will still create a line break)
|
||||||
|
Trix.config.blockAttributes.default.breakOnReturn = true
|
||||||
|
|
||||||
|
// Hack to fix buggy paragraph breaks
|
||||||
|
// Copied from https://github.com/basecamp/trix/issues/680#issuecomment-735742942
|
||||||
|
Trix.Block.prototype.breaksOnReturn = function () {
|
||||||
|
const attr = this.getLastAttribute()
|
||||||
|
const config = Trix.getBlockConfig(attr ? attr : 'default')
|
||||||
|
return config ? config.breakOnReturn : false
|
||||||
|
}
|
||||||
|
Trix.LineBreakInsertion.prototype.shouldInsertBlockBreak = function () {
|
||||||
|
if (this.block.hasAttributes() && this.block.isListItem() && !this.block.isEmpty()) {
|
||||||
|
return this.startLocation.offset > 0
|
||||||
|
} else {
|
||||||
|
return !this.shouldBreakFormattedBlock() ? this.breaksOnReturn : false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
/** Override editor configuration */
|
/** Override editor configuration */
|
||||||
this.overrideConfig(this.config)
|
this.overrideConfig(this.config)
|
||||||
|
this.enableBreakParagraphOnReturn()
|
||||||
/** Check if editor read-only mode is required */
|
/** Check if editor read-only mode is required */
|
||||||
this.decorateDisabledEditor(this.disabledEditor)
|
this.decorateDisabledEditor(this.disabledEditor)
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user