mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Add rich-text mode to CM6 (#10775)
Co-Authored-By: Mathias Jakobsen <3295293+hrjakobsen@users.noreply.github.com> GitOrigin-RevId: 00e015cb216bb8a52d083e71b34dbe91a7cd6cc5
This commit is contained in:
committed by
Copybot
co-authored by
Mathias Jakobsen
parent
7ec4aa899a
commit
0ae1a8facc
@@ -3,6 +3,8 @@ import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|||||||
import Tooltip from '../../../shared/components/tooltip'
|
import Tooltip from '../../../shared/components/tooltip'
|
||||||
import { sendMB } from '../../../infrastructure/event-tracking'
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
||||||
|
|
||||||
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
|
||||||
function Badge() {
|
function Badge() {
|
||||||
const content = (
|
const content = (
|
||||||
<>
|
<>
|
||||||
@@ -42,6 +44,10 @@ function EditorSwitch() {
|
|||||||
)
|
)
|
||||||
const [richText, setRichText] = useScopeValue('editor.showRichText')
|
const [richText, setRichText] = useScopeValue('editor.showRichText')
|
||||||
|
|
||||||
|
const [visual, setVisual] = useScopeValue('editor.showVisual')
|
||||||
|
|
||||||
|
const richTextOrVisual = richText || visual
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
event => {
|
event => {
|
||||||
const editorType = event.target.value
|
const editorType = event.target.value
|
||||||
@@ -49,22 +55,31 @@ function EditorSwitch() {
|
|||||||
switch (editorType) {
|
switch (editorType) {
|
||||||
case 'ace':
|
case 'ace':
|
||||||
setRichText(false)
|
setRichText(false)
|
||||||
|
setVisual(false)
|
||||||
setNewSourceEditor(false)
|
setNewSourceEditor(false)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'cm6':
|
case 'cm6':
|
||||||
setRichText(false)
|
setRichText(false)
|
||||||
|
setVisual(false)
|
||||||
setNewSourceEditor(true)
|
setNewSourceEditor(true)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'rich-text':
|
case 'rich-text':
|
||||||
setRichText(true)
|
if (params.has('cm_visual')) {
|
||||||
|
setRichText(false)
|
||||||
|
setVisual(true)
|
||||||
|
setNewSourceEditor(true)
|
||||||
|
} else {
|
||||||
|
setRichText(true)
|
||||||
|
setVisual(false)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMB('editor-switch-change', { editorType })
|
sendMB('editor-switch-change', { editorType })
|
||||||
},
|
},
|
||||||
[setRichText, setNewSourceEditor]
|
[setRichText, setVisual, setNewSourceEditor]
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -80,7 +95,7 @@ function EditorSwitch() {
|
|||||||
value="cm6"
|
value="cm6"
|
||||||
id="editor-switch-cm6"
|
id="editor-switch-cm6"
|
||||||
className="toggle-switch-input"
|
className="toggle-switch-input"
|
||||||
checked={!richText && !!newSourceEditor}
|
checked={!richTextOrVisual && !!newSourceEditor}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="editor-switch-cm6" className="toggle-switch-label">
|
<label htmlFor="editor-switch-cm6" className="toggle-switch-label">
|
||||||
@@ -93,7 +108,7 @@ function EditorSwitch() {
|
|||||||
value="ace"
|
value="ace"
|
||||||
id="editor-switch-ace"
|
id="editor-switch-ace"
|
||||||
className="toggle-switch-input"
|
className="toggle-switch-input"
|
||||||
checked={!richText && !newSourceEditor}
|
checked={!richTextOrVisual && !newSourceEditor}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="editor-switch-ace" className="toggle-switch-label">
|
<label htmlFor="editor-switch-ace" className="toggle-switch-label">
|
||||||
@@ -106,7 +121,7 @@ function EditorSwitch() {
|
|||||||
value="rich-text"
|
value="rich-text"
|
||||||
id="editor-switch-rich-text"
|
id="editor-switch-rich-text"
|
||||||
className="toggle-switch-input"
|
className="toggle-switch-input"
|
||||||
checked={!!richText}
|
checked={!!richTextOrVisual}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import './controllers/SwitchToPDFButton'
|
|||||||
import getMeta from '../../utils/meta'
|
import getMeta from '../../utils/meta'
|
||||||
import { hasSeenCM6SwitchAwaySurvey } from '../../features/source-editor/utils/switch-away-survey'
|
import { hasSeenCM6SwitchAwaySurvey } from '../../features/source-editor/utils/switch-away-survey'
|
||||||
|
|
||||||
|
const params = new URLSearchParams(window.location.search)
|
||||||
|
|
||||||
let EditorManager
|
let EditorManager
|
||||||
|
|
||||||
export default EditorManager = (function () {
|
export default EditorManager = (function () {
|
||||||
@@ -46,6 +48,7 @@ export default EditorManager = (function () {
|
|||||||
wantTrackChanges: false,
|
wantTrackChanges: false,
|
||||||
docTooLongErrorShown: false,
|
docTooLongErrorShown: false,
|
||||||
showRichText: this.showRichText(),
|
showRichText: this.showRichText(),
|
||||||
|
showVisual: this.showVisual(),
|
||||||
newSourceEditor: this.newSourceEditor(),
|
newSourceEditor: this.newSourceEditor(),
|
||||||
showSymbolPalette: false,
|
showSymbolPalette: false,
|
||||||
toggleSymbolPalette: () => {
|
toggleSymbolPalette: () => {
|
||||||
@@ -165,12 +168,27 @@ export default EditorManager = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showRichText() {
|
showRichText() {
|
||||||
|
if (params.has('cm_visual')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
this.localStorage(`editor.mode.${this.$scope.project_id}`) ===
|
this.localStorage(`editor.mode.${this.$scope.project_id}`) ===
|
||||||
'rich-text'
|
'rich-text'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showVisual() {
|
||||||
|
if (!params.has('cm_visual')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
this.localStorage(`editor.visual-mode.${this.$scope.project_id}`) ===
|
||||||
|
'visual'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
newSourceEditor() {
|
newSourceEditor() {
|
||||||
// only use the new source editor if the option to switch is available
|
// only use the new source editor if the option to switch is available
|
||||||
if (!getMeta('ol-showNewSourceEditorOption')) {
|
if (!getMeta('ol-showNewSourceEditorOption')) {
|
||||||
|
|||||||
@@ -292,6 +292,13 @@ export default FileTreeManager = class FileTreeManager {
|
|||||||
return this._findEntityByPathInFolder(this.$scope.rootFolder, path)
|
return this._findEntityByPathInFolder(this.$scope.rootFolder, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPreviewUrlByPath(path) {
|
||||||
|
const entity = this.findEntityByPath(path)
|
||||||
|
return entity
|
||||||
|
? `/project/${this.$scope.project._id}/file/${entity.id}`
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
_findEntityByPathInFolder(folder, path) {
|
_findEntityByPathInFolder(folder, path) {
|
||||||
if (path == null || folder == null) {
|
if (path == null || folder == null) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -330,6 +330,13 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.formatting-buttons-portal {
|
||||||
|
display: flex;
|
||||||
|
.formatting-btn--icon:last-of-type {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.formatting-btn {
|
.formatting-btn {
|
||||||
color: @formatting-btn-color;
|
color: @formatting-btn-color;
|
||||||
background-color: @formatting-btn-bg;
|
background-color: @formatting-btn-bg;
|
||||||
|
|||||||
@@ -28,5 +28,8 @@ declare global {
|
|||||||
isRestrictedTokenMember: boolean
|
isRestrictedTokenMember: boolean
|
||||||
_reportCM6Perf: () => void
|
_reportCM6Perf: () => void
|
||||||
_reportAcePerf: () => void
|
_reportAcePerf: () => void
|
||||||
|
MathJax: {
|
||||||
|
Hub: Record<string, any>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user