Mercurial > libervia-web
changeset 400:487dd238ab88
browser_side: bug fixes for microblog raw/rich edition toggle
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 11 Mar 2014 13:53:19 +0100 |
parents | 6e38d317bc16 |
children | ea03f898067f |
files | browser_side/base_panels.py browser_side/panels.py browser_side/richtext.py |
diffstat | 3 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/base_panels.py Tue Mar 11 12:55:31 2014 +0100 +++ b/browser_side/base_panels.py Tue Mar 11 13:53:19 2014 +0100 @@ -28,7 +28,7 @@ from pyjamas.ui.StackPanel import StackPanel from pyjamas.ui.TextArea import TextArea from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT -from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler +from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_ESCAPE, KeyboardHandler from pyjamas.ui.FocusListener import FocusHandler from pyjamas import DOM @@ -444,7 +444,7 @@ @param modifiedCb @param afterEditCb @param single_line: set to True to manage a single line editor. In that - case the edition will be terminated when the <enter> key is pressed. + case the edition will be terminated when <enter> or <escape> is pressed. @param listen_focus: set to True to terminate the edition when the focus is lost. Leave to None in order to use single_line's value. @param enhance_display: if True, the display text will be enhanced with addURLToText @@ -500,7 +500,8 @@ def onKeyPress(self, sender, keycode, modifiers): if not self.__single_line: return - if keycode == KEY_ENTER: # finish the edition + # XXX: it seems that pyjamas never catches the escape key + if keycode in (KEY_ENTER, KEY_ESCAPE): # finish the edition self.setFocus(False) if not self.__listen_focus: self.edit(False)
--- a/browser_side/panels.py Tue Mar 11 12:55:31 2014 +0100 +++ b/browser_side/panels.py Tue Mar 11 13:53:19 2014 +0100 @@ -609,6 +609,8 @@ """Toggle the editor between raw and rich text""" original_content = self.bubble.getOriginalContent() rich = not isinstance(self.bubble, richtext.RichTextEditor) + if rich: + original_content['syntax'] = Const.SYNTAX_XHTML def setBubble(text): self.content = text @@ -617,6 +619,8 @@ self.bubble.removeFromParent() self.__setBubble(True) self.bubble.setOriginalContent(original_content) + if rich: + self.bubble.setDisplayContent() # needed in case the edition is aborted, to not end with an empty bubble text = self.bubble.getContent()['text'] if not text:
--- a/browser_side/richtext.py Tue Mar 11 12:55:31 2014 +0100 +++ b/browser_side/richtext.py Tue Mar 11 13:53:19 2014 +0100 @@ -312,12 +312,17 @@ else: if not self.initialized: # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification - text = content['text'] - if 'title' in content and content['title']: - text = '<h1>%s</h1>%s' % (html_sanitize(content['title']), content['text']) - self.display.setContent({'text': text}) + self.setDisplayContent() self.display.edit(False) + def setDisplayContent(self): + """Set the content of the LightTextEditor which is used for display/wysiwyg""" + content = self._original_content + text = content['text'] + if 'title' in content and content['title']: + text = '<h1>%s</h1>%s' % (html_sanitize(content['title']), content['text']) + self.display.setContent({'text': text}) + def setFocus(self, focus): self.textarea.setFocus(focus)