# HG changeset patch # User souliane # Date 1394542399 -3600 # Node ID 487dd238ab884b51e855c14d064277c53f9813d7 # Parent 6e38d317bc16e5fc86ed3f6f993f4c760621b1c0 browser_side: bug fixes for microblog raw/rich edition toggle diff -r 6e38d317bc16 -r 487dd238ab88 browser_side/base_panels.py --- 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 key is pressed. + case the edition will be terminated when or 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) diff -r 6e38d317bc16 -r 487dd238ab88 browser_side/panels.py --- 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: diff -r 6e38d317bc16 -r 487dd238ab88 browser_side/richtext.py --- 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 = '

%s

%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 = '

%s

%s' % (html_sanitize(content['title']), content['text']) + self.display.setContent({'text': text}) + def setFocus(self, focus): self.textarea.setFocus(focus)