Modify

Opened 5 years ago

Last modified 8 months ago

#4970 accepted enhancement

Jump to edited section after edit

Reported by: kontakt at meitzner dot net Owned by: rjollos
Priority: normal Component: SectionEditPlugin
Severity: normal Keywords:
Cc: rjollos, hasienda 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 14 months ago.
tracsectionedit.js (631 bytes) - added by ms1014 14 months ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 5 years ago by rjollos

  • Cc rjollos added

comment:2 Changed 3 years ago by rjollos

  • Cc hasienda 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 3 years ago by rjollos

(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 3 years ago by rjollos

  • Owner changed from cbalan to rjollos
  • Status changed from new to assigned

comment:5 Changed 3 years ago by rjollos

  • Summary changed from Jump to edited section after edit to [Patch] Jump to edited section after edit

comment:6 Changed 3 years ago by rjollos

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 3 years ago by rjollos

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

comment:8 Changed 3 years ago by rjollos

  • Owner changed from rjollos to cbalan
  • Status changed from assigned to new
  • Summary changed from [Patch] Jump to edited section after edit to Jump 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 14 months ago by ms1014

Changed 14 months ago by ms1014

comment:9 Changed 14 months ago by ms1014

I found worked solution.

comment:10 Changed 14 months ago by rjollos

Great, thank you. I will take a look.

comment:11 Changed 8 months ago by phaebz

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

comment:12 Changed 8 months ago by rjollos

  • Owner changed from cbalan to rjollos
  • Status changed from new to accepted

Add Comment

Modify Ticket

Action
as accepted .
Author


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

 
Note: See TracTickets for help on using tickets.