Ticket #4970 (new enhancement)

Opened 4 years ago

Last modified 1 year ago

Jump to edited section after edit

Reported by: kontakt at meitzner dot net Assigned to: cbalan
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

Change History

06/30/09 00:39:19 changed by rjollos

  • cc set to rjollos.

01/24/12 14:41:44 changed by rjollos

  • cc changed from rjollos to rjollos, hasienda.

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

    old new  
    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

    old new  
    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: 

01/25/12 22:24:28 changed 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.

01/25/12 22:26:05 changed by rjollos

  • owner changed from cbalan to rjollos.
  • status changed from new to assigned.

01/25/12 22:26:45 changed by rjollos

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

01/27/12 06:47:45 changed 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.

01/27/12 06:49:28 changed by rjollos

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

01/27/12 22:45:35 changed 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 ...


Add/Change #4970 (Jump to edited section after edit)




Change Properties
Action