diff --git a/manuskript/ui/editors/fullScreenEditor.py b/manuskript/ui/editors/fullScreenEditor.py
index 5af61a49..4a04b044 100644
--- a/manuskript/ui/editors/fullScreenEditor.py
+++ b/manuskript/ui/editors/fullScreenEditor.py
@@ -13,7 +13,6 @@ from manuskript import settings
from manuskript.enums import Outline
from manuskript.functions import allPaths, drawProgress
from manuskript.ui.editors.locker import locker
-from manuskript.ui.editors.textFormat import textFormat
from manuskript.ui.editors.themes import findThemePath, generateTheme, setThemeEditorDatas
from manuskript.ui.editors.themes import loadThemeDatas
from manuskript.ui.views.MDEditView import MDEditView
@@ -65,11 +64,7 @@ class fullScreenEditor(QWidget):
self.topPanel.layout().addStretch(1)
- # Formatting
- self.textFormat = textFormat(self)
- self.topPanel.layout().addWidget(self.textFormat)
- self.topPanel.layout().addStretch(1)
-
+ # Close
self.btnClose = QPushButton(self)
self.btnClose.setIcon(qApp.style().standardIcon(QStyle.SP_DialogCloseButton))
self.btnClose.clicked.connect(self.close)
diff --git a/manuskript/ui/editors/mainEditor.py b/manuskript/ui/editors/mainEditor.py
index 1eafe227..f4013883 100644
--- a/manuskript/ui/editors/mainEditor.py
+++ b/manuskript/ui/editors/mainEditor.py
@@ -270,9 +270,6 @@ class mainEditor(QWidget, Ui_mainEditor):
else:
visible = True
- # Hides / show textFormat
- self.textFormat.updateFromIndex(index)
-
self.btnRedacFolderText.setVisible(visible)
self.btnRedacFolderCork.setVisible(visible)
self.btnRedacFolderOutline.setVisible(visible)
diff --git a/manuskript/ui/editors/mainEditor_ui.py b/manuskript/ui/editors/mainEditor_ui.py
index 45c8e6ff..d7f94e38 100644
--- a/manuskript/ui/editors/mainEditor_ui.py
+++ b/manuskript/ui/editors/mainEditor_ui.py
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'manuskript/ui/editors/mainEditor_ui.ui'
#
-# Created by: PyQt5 UI code generator 5.9
+# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!
@@ -65,17 +65,6 @@ class Ui_mainEditor(object):
self.horizontalLayout_19.addWidget(self.sldCorkSizeFactor)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_19.addItem(spacerItem)
- self.textFormat = textFormat(mainEditor)
- sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
- sizePolicy.setHorizontalStretch(0)
- sizePolicy.setVerticalStretch(0)
- sizePolicy.setHeightForWidth(self.textFormat.sizePolicy().hasHeightForWidth())
- self.textFormat.setSizePolicy(sizePolicy)
- self.textFormat.setMinimumSize(QtCore.QSize(20, 20))
- self.textFormat.setObjectName("textFormat")
- self.horizontalLayout_19.addWidget(self.textFormat)
- spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
- self.horizontalLayout_19.addItem(spacerItem1)
self.lblRedacWC = QtWidgets.QLabel(mainEditor)
self.lblRedacWC.setMinimumSize(QtCore.QSize(10, 0))
self.lblRedacWC.setText("")
@@ -110,4 +99,3 @@ class Ui_mainEditor(object):
self.btnRedacFullscreen.setShortcut(_translate("mainEditor", "F11"))
from manuskript.ui.editors.tabSplitter import tabSplitter
-from manuskript.ui.editors.textFormat import textFormat
diff --git a/manuskript/ui/editors/mainEditor_ui.ui b/manuskript/ui/editors/mainEditor_ui.ui
index 1110a34f..2950db94 100644
--- a/manuskript/ui/editors/mainEditor_ui.ui
+++ b/manuskript/ui/editors/mainEditor_ui.ui
@@ -51,8 +51,7 @@
-
-
+ ..
Alt+Up
@@ -141,35 +140,6 @@
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 20
- 20
-
-
-
-
-
@@ -237,12 +207,6 @@
-
- textFormat
- QWidget
- manuskript.ui.editors.textFormat.h
- 1
-
tabSplitter
QWidget
diff --git a/manuskript/ui/views/MDEditView.py b/manuskript/ui/views/MDEditView.py
index 849c72f2..2d31f716 100644
--- a/manuskript/ui/views/MDEditView.py
+++ b/manuskript/ui/views/MDEditView.py
@@ -1,12 +1,16 @@
#!/usr/bin/env python
# --!-- coding: utf8 --!--
-# from PyQt5.QtCore import
-# from PyQt5.QtGui import
+import re
+
+from PyQt5.QtCore import QRegExp, Qt
+from PyQt5.QtGui import QTextCursor
# from PyQt5.QtWidgets import
from manuskript.ui.views.textEditView import textEditView
from manuskript.ui.highlighters import MarkdownHighlighter
+# from manuskript.ui.editors.textFormat import textFormat
+# from manuskript.ui.editors.MDFunctions import MDFormatSelection
class MDEditView(textEditView):
@@ -19,3 +23,248 @@ class MDEditView(textEditView):
# Highlighter
self._textFormat = "md"
self._highlighterClass = MarkdownHighlighter
+
+ # def focusInEvent(self, event):
+ # """Finds textFormatter and attach them to that view."""
+ # textEditView.focusInEvent(self, event)
+ #
+ # p = self.parent()
+ # while p.parent():
+ # p = p.parent()
+ #
+ # if self._index:
+ # for tF in p.findChildren(textFormat, QRegExp(".*"),
+ # Qt.FindChildrenRecursively):
+ # tF.updateFromIndex(self._index)
+ # tF.setTextEdit(self)
+
+ ###########################################################################
+ # FORMATTING (#FIXME)
+ ###########################################################################
+
+ def applyFormat(self, _format):
+
+ if self._textFormat == "md":
+ if _format == "Bold": self.bold()
+ elif _format == "Italic": self.italic()
+ elif _format == "Code": self.verbatim()
+ elif _format == "Clear": self.clearFormat()
+
+ def bold(self): self.insertFormattingMarkup("**")
+ def italic(self): self.insertFormattingMarkup("*")
+ def strike(self): self.insertFormattingMarkup("~~")
+ def verbatim(self): self.insertFormattingMarkup("`")
+ def superscript(self): self.insertFormattingMarkup("^")
+ def subscript(self): self.insertFormattingMarkup("~")
+
+ def selectWord(self, cursor):
+ if cursor.selectedText():
+ return
+ end = cursor.selectionEnd()
+ cursor.movePosition(QTextCursor.StartOfWord)
+ cursor.setPosition(end, QTextCursor.KeepAnchor)
+ cursor.movePosition(QTextCursor.EndOfWord, QTextCursor.KeepAnchor)
+
+ def selectBlock(self, cursor):
+ cursor.movePosition(QTextCursor.StartOfBlock)
+ cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
+
+ def comment(self):
+ cursor = self.textCursor()
+
+ # Select begining and end of words
+ self.selectWord(cursor)
+
+ if cursor.hasSelection():
+ text = cursor.selectedText()
+ cursor.insertText("")
+ else:
+ cursor.insertText("")
+ cursor.movePosition(QTextCursor.PreviousCharacter,
+ QTextCursor.MoveAnchor, 4)
+ self.setTextCursor(cursor)
+
+ def commentLine(self):
+ cursor = self.textCursor()
+
+ start = cursor.selectionStart()
+ end = cursor.selectionEnd()
+ block = self.document().findBlock(start)
+ block2 = self.document().findBlock(end)
+
+ if True:
+ # Method 1
+ cursor.beginEditBlock()
+ while block.isValid():
+ self.commentBlock(block)
+ if block == block2: break
+ block = block.next()
+ cursor.endEditBlock()
+
+ else:
+ # Method 2
+ cursor.beginEditBlock()
+ cursor.setPosition(block.position())
+ cursor.insertText("")
+ cursor.endEditBlock()
+
+ def commentBlock(self, block):
+ cursor = QTextCursor(block)
+ text = block.text()
+ if text[:5] == "":
+ text2 = text[5:-4]
+ else:
+ text2 = ""
+ self.selectBlock(cursor)
+ cursor.insertText(text2)
+
+ def insertFormattingMarkup(self, markup):
+ cursor = self.textCursor()
+
+ # Select begining and end of words
+ self.selectWord(cursor)
+
+ if cursor.hasSelection():
+ start = cursor.selectionStart()
+ end = cursor.selectionEnd() + len(markup)
+ cursor.beginEditBlock()
+ cursor.setPosition(start)
+ cursor.insertText(markup)
+ cursor.setPosition(end)
+ cursor.insertText(markup)
+ cursor.endEditBlock()
+ cursor.movePosition(QTextCursor.PreviousCharacter,
+ QTextCursor.KeepAnchor, len(markup))
+ #self.setTextCursor(cursor)
+
+ else:
+ # Insert markup twice (for opening and closing around the cursor),
+ # and then move the cursor to be between the pair.
+ cursor.beginEditBlock()
+ cursor.insertText(markup)
+ cursor.insertText(markup)
+ cursor.movePosition(QTextCursor.PreviousCharacter,
+ QTextCursor.MoveAnchor, len(markup))
+ cursor.endEditBlock()
+ self.setTextCursor(cursor)
+
+ def clearFormat(self):
+ cursor = self.textCursor()
+ text = cursor.selectedText()
+ if not text:
+ self.selectBlock(cursor)
+ text = cursor.selectedText()
+ text = self.clearedFormat(text)
+ cursor.insertText(text)
+
+ def clearedFormat(self, text):
+ # FIXME: clear also block formats
+ for reg, rep, flags in [
+ ("\*\*(.*?)\*\*", "\\1", None), # bold
+ ("__(.*?)__", "\\1", None), # bold
+ ("\*(.*?)\*", "\\1", None), # emphasis
+ ("_(.*?)_", "\\1", None), # emphasis
+ ("`(.*?)`", "\\1", None), # verbatim
+ ("~~(.*?)~~", "\\1", None), # strike
+ ("\^(.*?)\^", "\\1", None), # superscript
+ ("~(.*?)~", "\\1", None), # subscript
+ ("", "\\1", re.S), # comments
+
+
+ # LINES OR BLOCKS
+ (r"^#*\s*(.+?)\s*", "\\1", re.M), # ATX
+ (r"^[=-]*$", "", re.M), # Setext
+ (r"^`*$", "", re.M), # Code block fenced
+ (r"^\s*[-+*]\s*(.*?)\s*$", "\\1", re.M), # Bullet List
+ (r"^\s*[0-9a-z](\.|\))\s*(.*?)\s*$", "\\2", re.M), # Bullet List
+ (r"\s*[>\s]*(.*?)\s*$", "\\1", re.M), # Code block and blockquote
+
+ ]:
+ text = re.sub(reg, rep, text, flags if flags else 0)
+ return text
+
+ def clearedFormatForStats(self, text):
+ # Remove stuff that musn't be counted
+ # FIXME: clear also block formats
+ for reg, rep, flags in [
+ ("", "", re.S), # comments
+ ]:
+ text = re.sub(reg, rep, text, flags if flags else 0)
+ return text
+
+ def titleSetext(self, level):
+ cursor = self.textCursor()
+
+ cursor.beginEditBlock()
+ # Is it already a Setext header?
+ if cursor.block().userState() in [
+ MS.MarkdownStateSetextHeading1Line2,
+ MS.MarkdownStateSetextHeading2Line2]:
+ cursor.movePosition(QTextCursor.PreviousBlock)
+
+ text = cursor.block().text()
+
+ if cursor.block().userState() in [
+ MS.MarkdownStateSetextHeading1Line1,
+ MS.MarkdownStateSetextHeading2Line1]:
+ # Need to remove line below
+ c = QTextCursor(cursor.block().next())
+ self.selectBlock(c)
+ c.insertText("")
+
+ char = "=" if level == 1 else "-"
+ text = re.sub("^#*\s*(.*)\s*#*", "\\1", text) # Removes #
+ sub = char * len(text)
+ text = text + "\n" + sub
+
+ self.selectBlock(cursor)
+ cursor.insertText(text)
+ cursor.endEditBlock()
+
+ def titleATX(self, level):
+ cursor = self.textCursor()
+ text = cursor.block().text()
+
+ # Are we in a Setext Header?
+ if cursor.block().userState() in [
+ MS.MarkdownStateSetextHeading1Line1,
+ MS.MarkdownStateSetextHeading2Line1]:
+ # Need to remove line below
+ cursor.beginEditBlock()
+ c = QTextCursor(cursor.block().next())
+ self.selectBlock(c)
+ c.insertText("")
+
+ self.selectBlock(cursor)
+ cursor.insertText(text)
+ cursor.endEditBlock()
+ return
+
+ elif cursor.block().userState() in [
+ MS.MarkdownStateSetextHeading1Line2,
+ MS.MarkdownStateSetextHeading2Line2]:
+ cursor.movePosition(QTextCursor.PreviousBlock)
+ self.setTextCursor(cursor)
+ self.titleATX(level)
+ return
+
+ m = re.match("^(#+)(\s*)(.+)", text)
+ if m:
+ pre = m.group(1)
+ space = m.group(2)
+ txt = m.group(3)
+
+ if len(pre) == level:
+ # Remove title
+ text = txt
+ else:
+ text = "#" * level + space + txt
+
+ else:
+ text = "#" * level + " " + text
+
+ self.selectBlock(cursor)
+ cursor.insertText(text)
diff --git a/manuskript/ui/views/textEditView.py b/manuskript/ui/views/textEditView.py
index 67a9d375..6090f2cc 100644
--- a/manuskript/ui/views/textEditView.py
+++ b/manuskript/ui/views/textEditView.py
@@ -10,10 +10,7 @@ from manuskript import settings
from manuskript.enums import Outline, World, Character, Plot
from manuskript import functions as F
from manuskript.models.outlineModel import outlineModel
-from manuskript.ui.editors.MDFunctions import MDFormatSelection
from manuskript.ui.highlighters import BasicHighlighter
-# from manuskript.ui.highlighters import MMDHighlighter
-from manuskript.ui.editors.textFormat import textFormat
from manuskript.ui import style as S
try:
@@ -544,32 +541,6 @@ class textEditView(QTextEdit):
QTextEdit.focusOutEvent(self, event)
self.submit()
- def focusInEvent(self, event):
- """Finds textFormatter and attach them to that view."""
- QTextEdit.focusInEvent(self, event)
-
- p = self.parent()
- while p.parent():
- p = p.parent()
-
- if self._index:
- for tF in p.findChildren(textFormat, QRegExp(".*"), Qt.FindChildrenRecursively):
- tF.updateFromIndex(self._index)
- tF.setTextEdit(self)
-
- def applyFormat(self, _format):
-
- if self._textFormat == "md":
-
- if _format == "Bold":
- MDFormatSelection(self, 0)
- elif _format == "Italic":
- MDFormatSelection(self, 1)
- elif _format == "Code":
- MDFormatSelection(self, 2)
- elif _format == "Clear":
- MDFormatSelection(self)
-
###############################################################################
# KEYBOARD SHORTCUTS
###############################################################################