Modify

Opened 15 years ago

Last modified 4 years ago

#4970 new enhancement

Jump to edited section after edit

Reported by: kontakt@… Owned by:
Priority: normal Component: SectionEditPlugin
Severity: normal Keywords:
Cc: Steffen Hoffmann Trac Release: 0.11

Description

When I edit a section of a large Article, it would be nice to see the browser jump to that section's heading after I hit the Save button. If for any reason this behavior was not wanted, it could maybe be toggled by a checkbox near that button.

I'm using SectionEditPlugin 0.1 on Trac 0.11.4, Ubuntu Hardy 8.4.2 Server, Opera 9.64 Browser.

Attachments (2)

web.diff (1.5 KB) - added by ms1014 11 years ago.
tracsectionedit.js (631 bytes) - added by ms1014 11 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 15 years ago by Ryan J Ollos

Cc: Ryan J Ollos added; anonymous removed

comment:2 Changed 12 years ago by Ryan J Ollos

Cc: Steffen Hoffmann added

Let me prefix this by saying I absolutely don't know what I'm doing here, but I hacked around with this enough to get the following patch working.

The changes are:

  1. In the Javascript function, I append the name of the heading's anchor to the url fragment.
  2. In filter_stream, I followed the pattern of inserting a hidden html element, by adding the anchor name as a hidden element.
  3. In pre_process_request, I get the anchor name and use that to construct a redirect, as is done for Trac tickets after a comment is posted. See web_ui.py in Trac 0.12 for reference.

I'm particularly unsure of step (2) Maybe there is a better way? Any help and suggestions would be greatly appreciated!!

Patch against [11180].

  • 0.12/tracsectionedit/htdocs/js/tracsectionedit.js

     
    55        var href_edit = document.location.href;
    66        href_edit = (href_edit.indexOf('?')==-1?'?':href_edit+'&')+"action=edit&section=";
    77        return this.filter("*[@id]").each(function(){
    8             $("<a class='anchor'>[<span>edit</span>]</a>").attr("href", href_edit + cnt++).attr("title", title).appendTo(this);
     8            var anchor = $(this).attr('id')
     9            $("<a class='anchor'>[<span>edit</span>]</a>").attr("href", href_edit + cnt++ + "&anchor=" + anchor).attr("title", title).appendTo(this);
    910        });
    1011    }
    1112   
  • 0.12/tracsectionedit/web_ui.py

     
    4949                req.args['text'] = "%s%s%s"%(req.args.get('section_pre'),
    5050                                             section_text,
    5151                                             req.args.get('section_post'))
     52                fragment = '#' + req.args.get('anchor')
     53                req.redirect(req.href.wiki(req.args['page']) + fragment)
    5254        return handler
    5355
    5456    def post_process_request(self, req, template, data, content_type):
     
    7072            section_element = html.input(type='hidden', name='section', id='section', value=req.args.get('section'))
    7173            pre_element = html.input(type='hidden', name='section_pre', id='section_pre', value=''.join(section_pre))
    7274            post_element = html.input(type='hidden', name='section_post', id='section_post', value=''.join(section_post))
     75            anchor_element = html.input(type='hidden', name='anchor', id='anchor', value=''.join(req.args.get('anchor')))
    7376           
    74             section_html = html(section_element, pre_element, post_element)
     77            section_html = html(section_element, pre_element, post_element,anchor_element)
    7578            stream = stream | Transformer('//textarea[@name="text"]').empty().append(section_text).before(section_html)
    7679            stream = stream | Transformer('//div[@id="content"]//h1').append("/%s (section %s)"%(section_text[:section_text.find('\n')].strip(" = \r\n"), req.args['section']))
    7780            if not self.preview_whole_page:

comment:3 Changed 12 years ago by Ryan J Ollos

(In [11192]) Refs #4970: Created a dev branch for version 0.3, which includes the patch from comment:2.

The 0.11 and 0.12 branches will be merged to produce a single code line for this plugin at the time version 0.3 is released.

comment:4 Changed 12 years ago by Ryan J Ollos

Owner: changed from Catalin BALAN to Ryan J Ollos
Status: newassigned

comment:5 Changed 12 years ago by Ryan J Ollos

Summary: Jump to edited section after edit[Patch] Jump to edited section after edit

comment:6 Changed 12 years ago by Ryan J Ollos

Well, this patch is no good because it does a redirect in pre_process_request and therefore the change doesn't get saved. It seems like the redirect needs to be done in post_process_request, however, I can't find a way to retrieve req.args['anchor'] in post_process_request, and I don't see a way to pass the value from pre_process_request to post_process_request. I spent about 5 hours on this, so I'm pretty much stuck at this point. It's possible the plugin needs some major redesign in order to implement this feature.

comment:7 Changed 12 years ago by Ryan J Ollos

(In [11204]) Refs #4970: Removing 0.12dev branch for now.

comment:8 Changed 12 years ago by Ryan J Ollos

Owner: changed from Ryan J Ollos to Catalin BALAN
Status: assignednew
Summary: [Patch] Jump to edited section after editJump to edited section after edit

I'm stuck on this after about 8 hours of effort and experimentation. Maybe someone will come along and help me out? ;) Otherwise, I'm moving on for now ...

Changed 11 years ago by ms1014

Attachment: web.diff added

Changed 11 years ago by ms1014

Attachment: tracsectionedit.js added

comment:9 Changed 11 years ago by ms1014

I found worked solution.

comment:10 Changed 11 years ago by Ryan J Ollos

Great, thank you. I will take a look.

comment:11 Changed 10 years ago by phaebz

Is there an update on this? Can I somehow help in testing?

comment:12 Changed 10 years ago by Ryan J Ollos

Owner: changed from Catalin BALAN to Ryan J Ollos
Status: newaccepted

comment:13 Changed 9 years ago by Ryan J Ollos

Status: acceptednew

Refocusing.

comment:14 Changed 7 years ago by Ryan J Ollos

Owner: Ryan J Ollos deleted

comment:15 Changed 4 years ago by Ryan J Ollos

Cc: Ryan J Ollos removed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.